Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I edit a Git commit that is hundreds of merges and merge conflicts into the past?

I need to modify a commit near the very beginning of my repository's history. Since that commit there have been probably hundreds of branches, merges, and merge conflicts.

I tried using interactive rebase with the --preserve-merges option, but I still get hundreds of conflict errors akin to "CONFLICT (content): Merge conflict in Foobar.cpp". Re-resolving them again manually is hugely impractical if not impossible.

I've heard of the 'rerere' feature, but only just now, so I haven't had it enabled.

like image 939
Walt D Avatar asked Dec 06 '25 06:12

Walt D


1 Answers

Rerere will not help you here.

You are looking for git filter-branch. Depending on your change, you may be able use the index-filter which will be faster than the tree filter. You will alter all of your subsequent SHA-1s by doing this.

Make sure to include the --all parameter so all of the references get updated. This is going to ruin any repo that uses this repo as a submodule as the SHA-1s will be referencing non-existent ones. You will need to do some more scripting to fix that.

Also, if anyone you work with had any unpushed commits, they will have to git rebase --onto their outstanding work onto the new place in the history.

In the coming years, we will hopefully see more support for performing such shenanigans - especially when submodules are involved.

like image 160
Adam Dymitruk Avatar answered Dec 07 '25 21:12

Adam Dymitruk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!