Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of git cherry-pick?

Tags:

git

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.

like image 865
andyortlieb Avatar asked Feb 08 '13 19:02

andyortlieb


People also ask

How do you reverse cherry-pick?

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.

What is the difference between revert and cherry-pick?

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.

What is the difference between cherry-pick and merge?

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.


2 Answers

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.

like image 82
Ryan Lundy Avatar answered Sep 17 '22 18:09

Ryan Lundy


The automated way to undo changes made by another commit is git revert.

like image 35
wRAR Avatar answered Sep 17 '22 18:09

wRAR