Make Git rebuild history using the current .gitignore

余生长醉 提交于 2019-12-22 08:12:07

问题


I did not use .gitignore to ignore files such as compiled binaries in my project, so these compiled binaries have been committed into the Git repository. And now I add .gitignore to my project. I want to rebuild the whole Git repo ignoring the files listed in .gitignore without losing any history. How can I do that?


回答1:


Remove those binary from the current cache if they were just added.

git rm --cached abinary

Then your .gitignore will automatically ignores those binaries.

But if they were committed in past commits, You won't loose history, but you still need to remove those binaries from said commit.
You will need either git filter-branch or bfg repo cleaner.

That will rewrite your history, and you will need a git push --force, so if you have more than one (yourself) collaborator, warn them in advance.



来源:https://stackoverflow.com/questions/39178676/make-git-rebuild-history-using-the-current-gitignore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!