彻底清除 git commit 的所有痕迹 [英] Completely remove every trace of git commit

查看:16
本文介绍了彻底清除 git commit 的所有痕迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下情况:我有一个包含很多提交的 git 存储库,我想删除一个在提交中引入的文件,该文件在几次更改后最终在提交中删除.所以现在我想从我的仓库中完全删除提交,因此做了:

Following situation: I have a git repo with a lot of commits, and I want to remove a file that was introduced in a commit changed in a few and finally deleted in a commit. So now I want to remove the commit completely from my repo and therefore did:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch UNWANTED_FILE' --prune-empty --tag-name-filter cat -- --all

git push -f origin master 

这很有效,我的历史被改写(改写了几次提交.但是:

This worked great and my history was rewritten (several commits were rewritten. However:

git log --all -- UNWANTED_FILE

我仍然显示两个条目,即提交只是删除文件并完成添加文件.

I still get two entries showing up, namely the commits were nothing else than removing the file and adding the file was done.

所有其他提交都完成了其他事情也完全消失了.我怎样才能删除这些提交的最后痕迹?

Alll the other commits were other things were done as well are completely gone. How can I remove the last traces of these commits as well?

推荐答案

删除提交的规范指南是 这里.它本质上给出了两条路线,git-filter-branchbfg.

The canonical guide to removing the commit is here. It in essence gives two routes, git-filter-branch, and bfg.

但是,如果您的意思是完全删除,那么您将错过该过程中的第 9 步,即:

However, if you really mean completely remove, you are missing step 9 in that process, i.e. :

git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now

实际上会删除未使用的引用.

which will actually delete the unused references.

还要注意,如果这些是不应该提交的敏感数据,或者它们只是巨大的(所以你不希望 git pull 再次将它们拉下来),你需要以确保将它们从以下位置移除:

Note also that if these are either sensitive data that should never have been committed, or they are just huge (so you don't want a git pull to pull them down again), you need to ensure they are removed from:

  • 上游存储库(和任何其他上游存储库)
  • 您的合作者的所有存储库(因此他们不会将其推回) - 通常要求他们删除其存储库并重新克隆会更容易.

还要注意那里关于让合作者重新设定基准而不是合并的评论.

Note also the comment in there about getting collaborators to rebase rather than merge.

这篇关于彻底清除 git commit 的所有痕迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆