我讀過在git中重命名文件時,應提交所有更改,執行重命名,然后暫存重命名的文件。Git將從內容中識別文件,而不是將其視為新的未跟蹤文件,并保留更改歷史記錄。但是,今晚僅此一次,我最終恢復為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現在認為我已經刪除了一個CSS文件,并添加了一個新文件。不是我想要的,讓撤消重命名,讓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時git第一次沒有識別出重命名?
3 回答

梵蒂岡之花
TA貢獻1900條經驗 獲得超5個贊
您必須將兩個修改后的文件添加到索引,然后git才能將其識別為移動。
mv old new和之間的唯一區別git mv old new是git mv還將文件添加到索引中。
mv old new那git add -A本來也可以
請注意,您不能只使用它,git add .因為那不會為索引添加刪除內容。
- 3 回答
- 0 關注
- 673 瀏覽
添加回答
舉報
0/150
提交
取消