Post

Git: Log

튜토리얼을 혹은 프로젝트를 진행하면서 분명 작동된다고 생각하고 commit했던 코드가 작동을 하지 않아 곤욕을 치른적이 있다. 이때 어디서 어떻게 잘못됬는지 찾기위해 이전에 commit 한 commit history를 확인하고 commit을 한 시점의 코드로 돌아가 프로그램이 잘 작동되는지 확인 할 수 있는데, 이때 git log 를 사용한다.

Git

Git History

$ git log

이하 commit history, q로 log를 빠져나갈 수 있다.

commit 6d79399...
Author: John Doe <username@email.com>
Date: Mon Oct 18 23:01:11 2021 -0400

    Add register & login actions on auth module

commit f4a693d...
Author: John Doe <username@email.com>
Date: Mon Oct 18 22:04:56 2021 -0400

    Add loading module

commit 9264889... (origin/master, master)
Merge: 758db8a 79f708c
Author: John Doe <username@email.com>
Date: Sun Oct 17 21:02:39 2021 -0400

    Merge pull request #13 from username/authentication

Git Checkout

Git에서 branch간의 이동에 git checkout을 쓰듯이 이전의 commit 단계의 코드를 git checkout을 통해 불러올 수 있다. commit hash id 의 앞 7자리를 사용해도 해당 시점으로 불러올 수 있다.

$ git checkout f4a693d

해당 시점의 코드에서 코드가 잘 작동되는지 확인하고 문제가 없을때 가장 최근에 작업했던 환경으로 돌아오려면 아래의 명령어로 돌아올 수 있다.

$ git checkout -

References:

This post is licensed under CC BY 4.0 by the author.