我运行了这个:
$ git mv README README.md
然后:
$ git commit -m "renamed" README.md
$ git push origin master
但是在 github 上,旧的 README 文件仍然存在于存储库中。 为什么?
最佳答案
因为您从未实际提交移动的删除部分。
http://www.kernel.org/pub/software/scm/git/docs/git-commit.html
The content to be added can be specified in several ways:
...
3) by listing files as arguments to the commit command, in which case the commit will ignore changes staged in the index, and instead record the current content of the listed files (which must already be known to git);
请注意这里的关键点:将忽略索引中暂存的更改。 git mv
暂存旧文件的删除和新文件的创建,但不提交它们。当您调用 git commit README.md
时,它会提交文件的新名称版本,但会忽略旧文件的分阶段删除。
试试这个顺序:
$ git mv README README.md
$ git commit -m "renamed"
$ git push origin master
关于git mv 不删除旧文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3904115/