Wednesday, January 21, 2009

HOWTO Revert your Git repo to a certain commit

Get the SHA1 hash of the commit that you wish to revert to.

% git log

...

commit 9ce5e10ac4fe43e9b580344454dd27172b6c4456
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 16:30:42 2009 +0800

show/hide icmp6box

commit f193cf92b2c925a2f3f71a713d766efd1e4d81e0
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 15:52:39 2009 +0800

Merge IPv6 changes

commit 1f9f2a95b7b42cf33e730535092e56e214fdb848
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 14:55:07 2009 +0800

Merge IPv6 changes

commit ce996bd3014b05fea5eaffd7c738c5c549fd7677
Author: Simon Cornelius P. Umacob
Date: Tue Jan 20 14:30:27 2009 +0800

add IPv6.inc and NetUtils.js

...

% git reset --hard ce996bd3014b05fea5eaffd7c738c5c549fd7677

HEAD now points to ce996bd3...

To go back to the "original" HEAD, find its SHA1 hash and reset your current HEAD to that state.

% git reflog
simoncpu@pfsense:/home/pfsense/simoncpu-IPv6> git reflog
74fb85b... HEAD@{0}: pull git@rcs.pfsense.org:pfsense/mainline.git: Fast forward
9ce5e10... HEAD@{1}: commit: show/hide icmp6box
f193cf9... HEAD@{2}: commit: Merge IPv6 changes
1f9f2a9... HEAD@{3}: commit: Merge IPv6 changes
ce996bd... HEAD@{4}: commit: add IPv6.inc and NetUtils.js
cfc4dab... HEAD@{5}: clone: from http://gitweb.pfsense.org/pfsense/simoncpu-IPv6.git

% git reset --hard 74fb85b

Note that you need not use the full SHA1 string to refer to an object.
The first few characters is enough.

No comments: