Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...