Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a git commit

Tags:

git

git-commit

Can you undo a past commit, that has long been merged into your git repository, via a git command? Or do you have to manually undo all the changes made in that commit?

like image 400
edwardmlyte Avatar asked Oct 03 '12 08:10

edwardmlyte


People also ask

How do I undo a specific commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.


1 Answers

You can always just revert the changes from a single commit by doing:

git revert <commit-id> 

note that this creates a new commit, undoing just those changes

E.g. git log --oneline

d806fc9 two 18cdfa2 bye 62c332e hello c7811ee initial 

Say I want to revert changes in commit 18cdfa2:

git revert 18cdfa2 

We now have: git log -1 -p

commit fb9d6627a71636503fc9a1eb4f725937c783ecee Author: Seth <sehe@mint12.(none)> Date:   Wed Oct 3 10:32:46 2012 +0200      Revert "bye"      This reverts commit 18cdfa27c964b66b624be1030250757b745d6866.  diff --git a/a b/a index 0907563..3b18e51 100644 --- a/a +++ b/a @@ -1 +1 @@ -bye world +hello world 
like image 112
sehe Avatar answered Oct 03 '22 23:10

sehe