Lets say our commit history looks like
1--2--3--4 ^ HEAD
Where 4 is the most recent commit.
Is there a way to replay the changes from commit 2 (the differences between 2 and 1) onto commit 4?
You are probably wondering why anyone would want to do that. Lets say that this is your production branch that is always supposed to be in a working state. Lets say that earlier, when the commit history looked like
1--2 ^ HEAD
You had a realization and thought that commit 2 might break everything, and so you quickly pushed out a revert commit, where commit 3 reverts commit 2. Then someone makes commit 4 that contains good content you want to keep. At this point you realize that commit 2 was actually ok, and so you want to replay it on top of 4.
git cherry-pick A
can do that.
See http://git-scm.com/docs/git-cherry-pick
Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).
For example git cherry-pick master~4 master~3
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