Git:删除意外添加到存储库的文件。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git:删除意外添加到存储库的文件。相关的知识,希望对你有一定的参考价值。

Note that you don't actually need a temporary branch, you can do this with a 'detached HEAD', but you need to take a note of the commit id generated by the git commit --amend step to supply to the git rebase command rather than using the temporary branch name.
  1. # create and check out a temporary branch at the location of the bad merge
  2. git checkout -b tmpfix <sha1-of-merge>
  3.  
  4. # remove the incorrectly added file
  5. git rm somefile.orig
  6.  
  7. # commit the amended merge
  8. git commit --amend
  9.  
  10. # go back to the master branch
  11. git checkout master
  12.  
  13. # replant the master branch onto the corrected merge
  14. git rebase tmpfix
  15.  
  16. # delete the temporary branch
  17. git branch -d tmpfix

以上是关于Git:删除意外添加到存储库的文件。的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Visual Studio 将文件夹添加到已复制到本地 git 存储库的 git 源代码控制?

忽略已经提交到Git存储库的文件[重复]

从存储库历史记录中删除提交 [重复]

是否有限制代码推送到 Git 存储库的首选做法? [关闭]

GIT代码管理总结

git操作