Git 101: Mundur atau Maju

Aktivitas maju atau mundur pada git dilakukan dengan git checkout $SHA1_commit-id. Berikut saya coba ilustrasikan contoh kasusnya:

$ vim source.txt
a
$ git add source.txt
$ git commit -m "initial version"
[master 9429e54] initial version
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 source.txt

Lalu, saya coba mulai isi boilerplate program ini

$ vim source.txt
a
b

Periksa status git

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       modified:   source.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

Saya lakukan add dan commit

$ git add source.txt
$ git commit -m "alpha version"
[master 40d7b3e] alpha version
 1 files changed, 1 insertions(+), 0 deletions(-)

Belakangan, saya tersadar bahwa isi boilerplate saya salah, dan saya ingin kembali ke bentuk awal. Saya lihat dulu log git.

$ git log
commit 40d7b3eff8c88e4592a1d72c001c9cfdcd98ed7f
Author: Zaki Akhmad 
Date:   Fri Jan 11 17:45:40 2013 +0700

    alpha version

commit 9429e54b20519cd4a9e77dda541ea2fec4a56a11
Author: Zaki Akhmad 
Date:   Fri Jan 11 17:42:31 2013 +0700

    initial version

Baiklah, saya putuskan untuk kembali ke kondisi awal. Yang perlu saya lakukan adalah checkout ke SHA1 commit.

$ git log
commit 40d7b3eff8c88e4592a1d72c001c9cfdcd98ed7f
Author: Zaki Akhmad 
Date:   Fri Jan 11 17:45:40 2013 +0700

    alpha version

commit 9429e54b20519cd4a9e77dda541ea2fec4a56a11
Author: Zaki Akhmad 
Date:   Fri Jan 11 17:42:31 2013 +0700

    initial version

$ git checkout 9429e54b20519cd4a9e77dda541ea2fec4a56a11
Previous HEAD position was 40d7b3e... alpha version
HEAD is now at 9429e54... initial version

Saya coba lihat kembali berkas source.txt

$ more source.txt
a

Yak, kembali ke kondisi awal.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>