Reputation: 1064
I would like to squash some commits that are older than a "conflicting" merge. E.g.:
main branch: A--B--C--D--G--H
dev branch: \-E--F----/
H is my current head, G is the conflicting merge (so a merge in which I resolved conflicts manually) and I would like to squash C and D - but if I try to do that, I'm getting rebase conflicts which are due to G having been a conflicting merge.
Can I squash C and D anyways and if yes, how? I would be interested in a solution in which I do not have to merge something manually again.
Additional info: git rebase -i B
does not even work when leaving all commits on "pick" - which should do nothing, right?
Upvotes: 0
Views: 148
Reputation: 60443
Don't use rebase for this, rebase can squash for you but it's built for much heavier lifting than ancestry-only rewrites like this, it does a load of (slow) prep work to enable any alterations you like along the way.
git replace --graft G B F # (put usable references to those commits here of course)
git filter-branch
and you've achieved everything the rebase would, vastly quicker.
Upvotes: 1
Reputation: 52008
First : by default, git rebase
completely ignores merge commits. You have to specify -r | --rebase-merges
to make git rebase
"aware" of your merge actions.
Combined with -i
: you will see that the sequencer script is a bit more elaborate, and allows you to describe the actions you want to take to replay your merges.
Second : in the scenario you describe, the content of the commits to merge will be the same as the original commits, so "solving conflicts" is equivalent to : "re-use the exact same content as G
".
If you hit a conflict when merging : try running
git restore --staged --source G -- .
# or using shorthands :
git restore -S -s G -- .
You may need to run git reset .
beforehand if you need to clear the "conflicting" flags from files in the index.
If your local git doesn't have git restore
(this command was added fairly recently, in git 2.27 -- june 2020) : try
git read-tree G
which should place the content of G
in the index.
Upvotes: 1