我读过在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.css
M 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第一次没有识别出重命名?
梵蒂冈之花