I have a commit history shown below:
B-X
/
A-C
\
D
I'd like to apply X to all branches B, C, D. Though cherry-pick does the trick, it makes history like this:
B-X
/
A-C-X
\
D-X
Now commit X is duplicated three times, which is very inconvenient if I have many branches. Ideally, I'd like the history to look like this:
B
/
A-X-C
\
D
Where X appears only once. This history is much cleaner. Which command should I use to achieve that?
The first main point is that the fix you are requesting will rewrite history, which is only something you should do if no-one else is using the branch. For instance if you move D to be after X, then anyone else who had previously checked out D will get very confused when they pull. You should only do this if no-one else is using it, or they know and expect the change.
// Make a new temporary branch starting at A, and move X into it.
git checkout -b tmp A
git cherry-pick X
// For each of B, C and D, rebase them on top of the temporary branch.
git checkout <branch>
git rebase tmp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With