我試圖使用Scott Chacon的'Pro Git'書籍學習git。在解釋如何分階段修改文件(第18頁)時,我瞭解到git add
這些文件已計劃提交,然後與git commit
合作。它提到一個提交已完成,只有添加的更改實際上將被提交,並且如果我再次更改一個文件,我必須在提交之前添加它,以便所有更改均已完成。文中說:`git commit`是否提交了未添加的更改
事實證明,Git的階段文件,正是因爲它是當你運行
git add
command.If立即提交,文件,因爲它是當你最後一次運行git add
版本命令是如何進入提交的,而不是當您運行git commit
時在工作目錄中顯示的文件版本。如果在運行git add
之後修改文件,則必須再次運行git add
才能暫存文件的最新版本。
不過,我想看到它自己,當一個不同的行爲:
$ git status #start clean
#On branch master
nothing to commit (working directory clean)
$ echo "hello" >> README.TXT
git-question> git add README.TXT #added change to README
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README.TXT
#
$ echo "good bye" >> README.TXT #change README after adding
$ git status #now 'hello' is added to be committed but not 'good bye'
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README.TXT
#
# 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: README.TXT
#
$ git commit -m "only hello" README.TXT #commit, i would expect just 'hello' gets commited
[master 86e65eb] only hello
1 file changed, 2 insertions(+)
$ git status #QUESTION: How come there's nothing to commit?!
# On branch master
nothing to commit (working directory clean)
所以現在的問題是:不應該僅僅git commit
提交了加入git add
的變化?如果是這樣,即使我沒有添加它,它爲什麼會提交第二個更改?
撞在釘子上!魔鬼真的在細節:D謝謝! – Chirlo