Git log 作为回顾check提交历史非常有用。下面列举一些常见的git log options, 帮助我们check提交历史
git log basic options
option | context
———– | —————–
-p | show the difference between different commits
-2 or number | only show the lastest 2 commits
–stat | only show the rows inserted/deleted
–name-only | only show the files changed
–name-status | only show the files created/deleted/modifed, marked as “C/D/M”
–pretty: | based on the option
pretty
pretty 选项的options option | context will show ——- | —————- oneline | commit_id + msg short | commit_id + msg + author full | commit_id + msg + author + commit_person fuller | commit_id + msg + author + commit_person + date format | customize the style for log
One example style for fuller:
commit id
Author: Nmme <email@address>
AuthorDate: Mon Aug 21 22:45:26 2017 -0700
Commit: Nmme <email@address>
CommitDate: Mon Aug 21 22:45:26 2017 -0700
commit msg
### Customize the log format
Details format list below:
‘%an’: author name ‘%ae’: author email ‘%ad’: author date ‘%ar’: author date, relative ‘%cn’: committer name ‘%ce’: committer email ‘%cd’: committer date (format respects –date= option) ‘%N’: commit notes ‘%h’: abbreviated commit hash ‘%s’: subject ‘%t’: abbreviated tree hash ‘%C(color_name)’ : add color for the view
some examples for format
git log --pretty=format:"%h - %an, %ar : %C(red)%s"
ca82a6d - John Snow, 1 months ago : Go back to DragonStone
085bb3b - John Snow, 1 months ago : get a walker
a11bef0 - John Snow, 1 months ago : first go outside to the wall
### 图形化
One important option --graph, show graph about the git branch tree. Such as:
git log --pretty=format:"%h %s" --graph
gitk is a grgphic tool used by git to show the git branch tree.
### 简化Git log语法
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Difference between author and committer author: the person who made the changes committer: the person who submitted the changes to repo.