Git Study

Git - 커밋 히스토리 조회하기

marinee 2020. 3. 1. 16:46

gitpro book을 참고한 내용.

Commit history 조회하기

새로 저장소를 만들어서 몇번 커밋했을 수도 있고, Commit history가 있는 저장소를 clone 했을 수도 있다. 어쨌든 가끔 저장소의 history가 보고싶다면? git log.

이 예제에서는 "simplegit" 이라는 단순한 프로젝트를 사용.

$ git clone https://github.com/schacon/simplegit-progit  

이 프로젝트 디렉토리에서 git log를 실행하자.

$ git log
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 16:40:33 2008 -0700

    removed unnecessary test

commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 10:31:28 2008 -0700

    first commit

저장소의 commit history를 시간 순으로 보여준다. 가장 최근의 commit이 가장 먼저 나온다. 그리고 이어서 각 commit의 SHA-1 Checksum, author, email, committed date, commit message를 보여준다.
여기서 몇가지 옵션을 줄 수 있는데, -p, --patch는 유용하다. -p는 각 commit의 diff 결과를 보여준다. 여기에 '-2'를 주면, 최근 두개의 결과만을 보여주게 된다.

$ git log -p -2
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

diff --git a/Rakefile b/Rakefile
index a874b73..8f94139 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
 spec = Gem::Specification.new do |s|
     s.platform  =   Gem::Platform::RUBY
     s.name      =   "simplegit"
-    s.version   =   "0.1.0"
+    s.version   =   "0.1.1"
     s.author    =   "Scott Chacon"
     s.email     =   "schacon@gee-mail.com"
     s.summary   =   "A simple gem for using Git in Ruby code."

commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 16:40:33 2008 -0700

    removed unnecessary test

diff --git a/lib/simplegit.rb b/lib/simplegit.rb
index a0a60ae..47c6340 100644
--- a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -18,8 +18,3 @@ class SimpleGit
     end

 end
-
-if $0 == __FILE__
-  git = SimpleGit.new
-  puts git.show
-end

이 옵션은 diff를 실행한 것과 같은 결과를 출력하므로 동료가 무엇을 commit했는지 재빨리 리뷰하는데 유용하다.
git log --stat을 쓰면 각 commit의 통계정보를 알 수 있다. 이 옵션으로 어떤 파일이 수정되었는지, 얼마나 많은 파일이 변경되었는지, 얼마나 많은 라인을 추가/삭제했는지 보여줌. 요약정보는 가장 뒤쪽에 보여준다. 이 외에 몇가지 git log옵션에는 다음과 같은 것들이 있다.

  • git log --pretty=oneline : 각 커밋을 1-line으로 요약, 많은 커밋을 조회할때 사용

  • git log --pretty=format에 쓸 몇가지 유용한 옵션은 다음 링크를 활용하자.

https://git-scm.com/book/ko/v2/Git%EC%9D%98-%EA%B8%B0%EC%B4%88-%EC%BB%A4%EB%B0%8B-%ED%9E%88%EC%8A%A4%ED%86%A0%EB%A6%AC-%EC%A1%B0%ED%9A%8C%ED%95%98%EA%B8%B0#pretty_format