我的当前git status看起来像这样:
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: docs/file3.org
# modified: src/main/R/lib.R
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: docs/file3.org
# modified: src/main/R/lib.R
Run Code Online (Sandbox Code Playgroud)
我想首先将阶段性更改提交docs/file3.org,然后再进行其他阶段性更改.但是,如果我这样做git commit -m '...' docs/file3.org,它将提交对该文件的分阶段和非分阶段更改.
是否有捷径可寻?或者我是否需要进行未stash分级的更改,取消其中一个文件,提交另一个,重新设置,提交和stash pop?
由于您只需要将暂存的更改提交到文件,因此您可以隐藏,保持索引更改不变,然后提交文件.
git stash --keep-index #Note that the staged changes also become part of the stash
git commit -m "Commit only one file" docs/file3.org
git commit -m "Commit other staged changed"
git stash pop
# This may raise CONFLICTS since the stash includes the earlier staged changes.
# In case of conflict, the stash is not popped, so you need to drop it explicitly.
Run Code Online (Sandbox Code Playgroud)
真正奇怪的是, git-scm 书完全按照您所描述的方式解释了暂存:
同一文件的未暂存更改不会与提交一起进行,只会与暂存更改一起进行。
查看: http: //git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository#Staging-Modified-Files
我开始测试,无论我暂存的同一文件发生了什么更改,所有更改都会随提交一起进行。
| 归档时间: |
|
| 查看次数: |
8562 次 |
| 最近记录: |