I have the following commit history:
(master) (topic) (quickfix)
a -> b -> c -> d -> e
I want to modify it so that it looks like so:
(master, quickfix) (topic)
a -> e -> b -> c -> d
In other words, master
was at a commit a
. I started working on a topic
branch, but while on that branch I saw an issue and made a fix to unrelated code. I did this in a quickfix
branch, but the branch was from topic
instead of master
. I'd like to merge quickfix
back into master
, but without any of the changes that were made in topic
.
I know I can use diff/apply to ultimately get where I want to go, but this has happened to me a few times and I find the diff/apply workflow a little cumbersome. Is there a feature in git that makes this easier?
There isn't one command to do this, but a relatively simple sequence can do it, run while working on the master
branch:
# make it so that it's as if quickfix were branched off of master instead
# of topic
git rebase --onto master topic quickfix
# proceed as normal
git merge quickfix
git rebase master topic
The reason I didn't understand this at first was that I wasn't aware of the --onto
option for git rebase
. I found out about it while reading git help rebase
, which had a similar enough example.
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