0 votes
1 view
in DevOps and Agile by (30k points)

What is the simplest way to undo a particular commit that is:

not in the head or HEAD

Has been pushed to the remote.

Because if it is not the latest commit,

git reset HEAD

doesn't work. And because it has been pushed to a remote,

git rebase -i


git rebase --onto

will cause some problem in the remotes.

More so, I don't want to modify the history really. If there was bad code, it was there in history and can be seen. I just want it out in the working copy, and I don't mind a reverse merge commit.

In other words, what is the Git equivalent of the following svn commands:

svn merge -r 303:295 <REPO LINK>

which removes all changes from 295 to 302 by reverse merging all changes in those revisions, as a new commit.

svn merge -c -302 ^/trunk

which undoes the 302 commit, of course by adding another commit that reverse merges the changes from that respective commit.

I thought it should be a fairly simple operation in Git and a fairly common use case. What else is the point of atomic commits?

We have staging stashing and all to ensure the commits are perfectly atomic, shouldn't you be able to undo one or more of those atomic commits easily?

1 Answer

0 votes
by (51.2k points)

For this, we need to Identify the hash of the commit, using 

git log

then revert the commit for that use 

git revert <commit> 

And then to create a new commit that removes these changes. 

In a way, git revert is the converse of git cherry-pick. Where cherry-pick applies a patch to a branch that’s missing. But the revert will remove from the branch.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !