Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

github - Completely remove every trace of git commit

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...