git mv 不删除旧文件

标签 git github

我运行了这个:

 $ 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/

相关文章:

rest - ReSpec vs Bikeshed : How to document and publish a standard REST API interface to be implemented by a number of vendors?

git - SourceTree - 致命无法创建 .git/index.lock 文件存在

git - 如何撤消 git update-index?

windows - 使用 git 时 Mac/Windows 的文件权限问题

git - 有没有办法通过命令行或 git 将 GitHub 中的所有存储库/存储库设为私有(private)?

git - 在代码管理方面,TFS 比 GIT 好吗?

git - 如何在 Jenkins 中设置 "Git Changelog"?

c# - 无法在 Azure DevOps 上完成 pull 请求

HTML 不会链接到 GitHub 存储库中的 CSS

github - 如何在我的 github 博客上使用 Markdown 制作流程图