I recently had to pull a feature out of our 'dev' branch because it's being put on hold until a later date.
To do so, I created a branch whose parent is on 'dev' one commit before the first feature commit (the first feature commit was a squashed merge from another branch.) I then cherry-picked all of the feature commits from dev into the new branch. Finally I made one big revert commit on dev to remove those cherry-picked commits.
Now I want to rebase the new branch on dev to get it up to date. If I run "git rebase dev", the head of the new branch becomes the big revert, so the feature is lost.
With "git rebase --strategy=ours dev" all the commits in the feature branch are skipped with the message "Already applied: 0001...".
How can I rebase the feature branch onto dev such that all the commits on the feature are applied to the head of dev?
Maybe there's a better way to go about this process than what I've described here?
The git revert commit command is substantially similar to the command git cherry-pick commit with one important difference: it applies the inverse of the given commit . Thus, this command is used to introduce a new commit that reverses the effects of a given commit.
Once you have git cherry-pick down, you can start off by thinking of git rebase as being a faster way to cherry-pick all of the commits in a given branch at once, rather than having to type out their IDs separately.
You can cherry-pick a commit on one branch to create a copy of the commit with the same changes on another branch. If you commit changes to the wrong branch or want to make the same changes to another branch, you can cherry-pick the commit to apply the changes to another branch.
You can fix this by checking out your feature branch and doing:
git rebase --onto dev HEAD~<number of commits you care about> --force-rebase
This instructs git to replay the commit range that you specify and to ignore whether or not the commit occurred at a point in time prior to the commits on dev.
Note that this will leave you with a history that looks like:
<did some work> -- <reverted all of that work> -- <re-did that work>
which may not be all that useful to you. Some of the other answers here detail how you can get a cleaner history by rewriting it, depending on your team's tolerance for history rewriting.
Assuming that you don't mind rewriting history, a better way to do whole thing would have been an interactive rebase:
This will
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