简体   繁体   中英

How to clean up obsolete rewritten commits in git after a git-filter-branch

I needed to remove a couple of obsolete files from the git history, so I followed the approach of using "git filter-branch ..." as suggested in various questions and in the git manual. After running the command, I now see the all rewritten commits in my "git log", so instead of the original 10 commits, I now have around 30 commits (after removing 3 files).

I tried the suggestions provided in various answers to remove the ".git/refs/originals" and then "git reflog expire..." and "git gc --aggressive --prune" etc. but I still have 30 commits. I also tried the suggestion of cloning my repository into a new one, and the new one has 30 commits as well. I also pushed to github and now that has 30 commits.

Is there anything I am missing to get rid of the overwritten commits (without doing a rebase operation). My goal is to only get rid of the "duplicate" commits, not to squash commits.

Thanks!

Exactly what commands did you run? It's probably best to make a fresh clone of this repo and try again. There is a guide on help.github that might help.

You can also try rebase -i --preserve-merges or script git cherry-pick --no-commit to do what you want.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM