Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

how to undo an already pushed commit

Note: the steps below does not remove the previous commit.
It simply reverts it to what it was.

Step one is to ensure that you are on a clean working directory.
You shouldn't have any open new changes.

Then you'll need to find the hash for the specific commit you are trying to undo.
You can find them on your online Repo (like GitHub, for instance).

Take this hash and then head back over to your terminal.
You can now revert this commit by executing the following command.

for example if the hash is f193a70


$ git revert f193a70 --no-edit


Note: The --no-edit is optional. It won't prompt you to edit
the commit message that way

Once executed, you'll note that it will do the opposite of the commit locally.

The command will return the files to what they used to be before.

Now all that's left is to push the reverted code.


$ git push


When you view your changes, you'll see the old commit is still there,
but a new revert commit replaces the changes.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #undo #pushed #commit
ADD COMMENT
Topic
Name
4+1 =