Is there an effective opposite of git cherry-pick? For instance some time ago, I had to make some temporary changes to disable a set of features due to a business process not being ready. Now that that business process is ready I'd like to simply remove the commits and their effects. While I could of course just look at the diffs of those commits and figure out what all needed to be done, it would be interesting to know if those commits way back in the history could be un-done without resetting and losing all that came after them.
A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit. Stash your current changes so you can reapply them after resetting the commit.
git cherry-pick is like "Convert the specified commit into a patch and apply this patch here". git revert is like "Convert the specified commit into a patch, 'invert' this patch (like in patch -R ) and apply it here". Both commands can lead to conflicts.
With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined. The cherry-pick command allows you to select individual commits for integration.
git revert
isn't the opposite of git cherry-pick
. git rebase -i
is.
git revert
adds a new commit that removes the changes made by one or more old commits. It doesn't remove the original commits.
git rebase -i
will show you a list of commits from your current commit, going back to the last commit not on your upstream branch. Then you can edit, rearrange, change the commit message, and even delete commits from this list.
Keep in mind that if you've already pushed the commits you want to remove, you'll need to OK removing them with your teammates, because they'll have to make adjustments once you push the new history with the removed commits.
The automated way to undo changes made by another commit is git revert
.
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