andyortlieb
andyortlieb

Reputation: 2406

Opposite of git cherry-pick?

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.

Upvotes: 40

Views: 12585

Answers (2)

Ryan Lundy
Ryan Lundy

Reputation: 210140

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.

Upvotes: 35

wRAR
wRAR

Reputation: 25693

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

Upvotes: 28

Related Questions