我讀過在git中重命名文件時(shí),應(yīng)提交所有更改,執(zhí)行重命名,然后暫存重命名的文件。Git將從內(nèi)容中識(shí)別文件,而不是將其視為新的未跟蹤文件,并保留更改歷史記錄。但是,今晚僅此一次,我最終恢復(fù)為git mv。> $ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: index.html#將我在Finder中的樣式表從重命名iphone.css為mobile.css> $ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: index.html## Changed but not updated:# (use "git add/rm <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## deleted: css/iphone.css## Untracked files:# (use "git add <file>..." to include in what will be committed)## css/mobile.css所以git現(xiàn)在認(rèn)為我已經(jīng)刪除了一個(gè)CSS文件,并添加了一個(gè)新文件。不是我想要的,讓撤消重命名,讓git完成工作。> $ git reset HEAD .Unstaged changes after reset:M css/iphone.cssM index.html回到我開始的地方。> $ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: index.html#讓我們git mv改為使用。> $ git mv css/iphone.css css/mobile.css> $ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## renamed: css/iphone.css -> css/mobile.css## Changed but not updated:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: index.html#看起來我們很好。那么,為什么在我使用Finder時(shí)git第一次沒有識(shí)別出重命名?
3 回答

梵蒂岡之花
TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
您必須將兩個(gè)修改后的文件添加到索引,然后git才能將其識(shí)別為移動(dòng)。
mv old new和之間的唯一區(qū)別git mv old new是git mv還將文件添加到索引中。
mv old new那git add -A本來也可以
請(qǐng)注意,您不能只使用它,git add .因?yàn)槟遣粫?huì)為索引添加刪除內(nèi)容。
- 3 回答
- 0 關(guān)注
- 672 瀏覽
添加回答
舉報(bào)
0/150
提交
取消