Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop old commit: `git rebase` causes merge conflicts

Unfortunately we accidently checked in a large binary file some time ago and until today nobody noticed. Now I want to drop that commit and have the remaining history as it is. I know about the caveats of changing pushed history but in this case I cannot avoid it.

I have been trying to achieve that for ~1h but fail to get it. The best command I found is

git rebase --interactive --preserve-merges $(EVIL_COMMIT)^

and in the editor commenting out the 1st commit which is the evil one.

Unfortunately git rebase stops at merges and prompts for manual resolution of merge conflicts. The evil commit only adds some example files our software shall compute for testing purposes. Thus their shouldn't be any conflict with the example files just missing.

  1. I do not understand where the merge conflicts originate from. Somebody can explain?
  2. How to resolve that?

I've spent quite a lot of time at Google and SO search. Some threads cover a similar topic but either syntax used is not available in today's Git version anymore or it didn't work for me (I only described one method above because it's the easiest approach).

like image 766
Daniel Böhmer Avatar asked Nov 01 '11 16:11

Daniel Böhmer


1 Answers

I'd go with filter-branch:

git filter-branch --prune-empty --index-filter '
  git rm --cached --ignore-unmatch path/to/file
' --all
like image 159
knittl Avatar answered Oct 22 '22 19:10

knittl