完全删除每一个git commit的踪迹 [英] Completely remove every trace of git commit

查看:200
本文介绍了完全删除每一个git commit的踪迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下情况:我有一个提交了很多提交的git仓库,我想删除一个文件,这个文件是在一个提交中被改变的提交中引入的,并且最终在提交中被删除。所以现在我想完全从我的回购库中删除提交,因此:


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


git push -f原始大师



这很棒,我的历史被重写但是:


git log --all - UNWANTED_FILE


我仍然看到两个条目,即提交是除去文件并添加文件完成的其他内容。



所有其他提交的提交都完成了,其他提交也完全没有了。我怎样才能删除这些提交的最后一个跟踪?

解决方案

删除提交的规范指南是此处

本质上给出两条路线, git-filter-branch bfg



然而,如果你的意思是完全移除,那么你在这个过程中缺少了第9步,即:

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

这实际上会删除未使用的引用。



还要注意,如果这些是不应该提交的敏感数据,或者它们只是巨大的(所以你不想让 git pull 再次拉它们),你需要确保它们被移除:




  • 上游回购(和任何其他上游回购)

  • 所有协作者的回购协议) - 请求他们删除他们的repo和reclone通常更容易。



还要注意关于让合作者重新署名的评论而不是合并。


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?

解决方案

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

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.

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:

  • The upstream repo (and any other upstream repos)
  • All your collaborator's repos (so they don't push them back) - it's normally easier to ask them to delete their repo and reclone.

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

这篇关于完全删除每一个git commit的踪迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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