Git 히스토리 조회하기 : $ git log
- 저장소의 커밋 히스토리를 시간순으로 보여준다. 즉, 가장 최근의 커밋이 가장 먼저 나온다.
- 각 커밋의 SHA-1 체크섬, 브랜치, 저자 이름, 저자 이메일, 커밋한 날짜, 커밋 메시지를 보여준다.
- Ex▼)
$ 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
- '-p', '--patch' 옵션 : 각 커밋의 diff 결과 조회
$ git log -p |
- '-<숫자>' 옵션 : <숫자>갯수만큼의 결과만 조회
$ git log -<숫자> |
ㄴ> ex▼) $ git log -p -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
- '--stat' 옵션 : 히스토리의 통계를 출력 (= 각 커밋의 통계 정보를 조회)
$ git log --stat |
ㄴ> 어떤 파일이 수정됐는지, 얼마나 많은 파일이 변경됐는지, 또 얼마나 많은 라인을 추가하거나 삭제했는지 보여준다.
ㄴ> 요약정보는 가장 뒤쪽에 보여준다.
ㄴ> ex▼)
$ git log --stat
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
Rakefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
removed unnecessary test
lib/simplegit.rb | 5 -----
1 file changed, 5 deletions(-)
commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 10:31:28 2008 -0700
first commit
README | 6 ++++++
Rakefile | 23 +++++++++++++++++++++++
lib/simplegit.rb | 25 +++++++++++++++++++++++++
3 files changed, 54 insertions(+)
- '--pretty' 옵션 : 히스토리 내용을 출력 형식 설정 (>>여러 형식들 중에 하나를 선택)
$ git log --pretty=<출력 형식 옵션명> |
ㄴ> <출력 형식 옵션>
1. oneline 옵션 : 각 커밋을 한 라인으로 보여준다. ㄴ> ex) $ git log --pretty=oneline 2. short, full, fuller 옵션 : 정보를 조금씩 가감해서 보여준다. 3. format 옵션 : 나만의 포맷으로 결과를 출력 ㄴ> 특히 결과를 다른 프로그램으로 파싱하고자 할 때 유용 ㄴ> 옵션을 사용하면 포맷을 정확하게 일치시킬 수 있기 때문에 Git을 새 버전으로 바꿔도 결과 포맷이 바뀌지 않는다. ㄴ> [git log --pretty=format 의 유용한 옵션] ㄴ> format 옵션에는 '저자(Author)'와 '커미터(Committer)'를 지정할 수 있는데 둘의 차이는 아래와 같다. ㄴ 저자(Author) : 원래 작업을 수행한 원작자이고 ㄴ 커미터(Committer) : 마지막으로 이 작업을 적용한(저장소에 포함시킨) 사람 |
ㄴ> ex▼) $ git log --pretty=format:"%h - %an, %ar : %s"
$ git log --pretty=format:"%h - %an, %ar : %s"
ca82a6d - Scott Chacon, 6 years ago : changed the version number
085bb3b - Scott Chacon, 6 years ago : removed unnecessary test
a11bef0 - Scott Chacon, 6 years ago : first commit
- '--graph' 옵션 : 브랜치를 그래프로 출력
$ git log --graph |
ㄴ> oneline 옵션과 format 옵션과 사용할 때 매우 유용하다. Ex▼)
$ git log --pretty=format:"%h %s" --graph
* 2d3acf9 ignore errors from SIGCHLD on trap
* 5e3ee11 Merge branch 'master' of git://github.com/dustin/grit
|\
| * 420eac9 Added a method for getting the current branch.
* | 30e367c timeout code and tests
* | 5a09431 add timeout protection to grit
* | e1193f8 support for heads with slashes in them
|/
* d6016bc require time for xmlschema
* 11d191e Merge branch 'defunkt' into local
ㄴ> $ git log --oneline --decorate --graph --all : 갈라져 나온 다른 브랜치들도 확인 가능
히스토리 조회 범위를 제한하는 옵션
'-<숫자>' | <숫자>갯수만큼의 결과 조회 |
'--since', '--until' | 시간을 기준으로 조회 - 다양한 형식을 지원한다. ㄴ> ex) 정확한 날짜인 "2008-01-15", 상대적인 기간인 "2 years 1 day 3 minutes ago" 등 - ex) 지난 2주 동안 만들어진 커밋들만 조회하는 명령 ㄴ> $ git log --since=2.weeks |
'--author' | 저자를 지정하여 조회 |
'--grep' | 커밋 메시지에서 키워드를 검색 |
'-S' | 추가되거나 제거된 내용 중에 특정 텍스트가 포함되어 있는지를 검색 $ git log -S <검색할 텍스트> |
'--<경로명>' | 파일 경로로 검색하는 옵션 $ git log ./asset asset폴더와 하위에 포함된 파일의 commit만 조회 $ git log . 현재 폴더 조회 |
그 외 범위제한 옵션들 | 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#limit_options |
- 기타 외 $git log 옵션들 : 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#log_options
END!
스터디 도움 참조 블로그 (References)
- 버전 관리(VC) 위키백과 https://ko.wikipedia.org/wiki/%EB%B2%84%EC%A0%84_%EA%B4%80%EB%A6%AC - 누구나 쉽게 이해할 수 있는 Git 입문 https://backlog.com/git-tutorial/kr/ /입문편/Git의 기본/이력을 관리하는 저장소 https://backlog.com/git-tutorial/kr/intro/intro1_2.html - git--distributed-even-if-your-workflow-isnt (Pro Git Book) https://git-scm.com/book/en/v2 - git--distributed-even-if-your-workflow-isnt (Pro Git Book) / ch2. 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 |