Let's say I have multiple commits, like this:
---A---B---C---D
\
E---F---G
\
H
Now let's say I amend a change to B, creating commit B'
B'
/
---A---B---C---D
\
E---F---G
\
H
How can I rebase every descendant of B on B'?
B'---C'---D'
/ \
---A---B E'---F'---G'
\
H'
In my workflow there are usually multiple branches pointing to these descendant commits and ideally I wouldn't execute a git rebase command for each branch.
In my previous company we used Mercurial, where after amending a commit you could just run 'hg evolve' and it would rebase all descendants of that commit on the new one.
Is there a way to do this in a single command in git? I've been trying to write a script to recursively cherry-pick all descendants based on the commit graph (parsed from git rev-list --children --all
) but it feels like there must be an easier way.
git rebase --update-refs
. – Slenderizerebase --update-refs
looks similar but is doing it only for a branch pointing to a commit that will be rebased (so a very specific edge case). Maybe there is a tool doing that (that I don't know) but the painful side will always be to checkout each branch of the tree to do a rebase that will allow to manage conflicts. Building your own tool using new experimentalgit replay
command if you don't need to manage conflicts could be an idea: github.blog/2024-02-23-highlights-from-git-2-44/… – Isocyanidegit replay --onto B' B..D B..G B..H | git update-ref --stdin
. It should work as long as there is no conflicts and none of the branches replayed is checked out (otherwiseupdate-ref
will fail on it) – Isocyanide