基础命令:
查看版本: git --version
log命令:
git log: 显示 commit 记录
log参数:
--pretty:
输出 log 的格式.
--pretty参数:
参数 | 描述 |
---|---|
use email headers like From and Subject | |
format | specify own format |
full | all parts of commit messages |
fuller | like full and includes dates |
medium | most parts of messages |
oneline | commit-ids and subject of messages |
raw | the raw commits |
short | few headers and only subject of messages |
pretty 自定义格式转义字符:
如何查看到下面的参数,输入下面命令后 git log --pretty=format:%, 使用 tab 键这个老朋友显示出来(tab键功能,列出可选项,或者直接补充完整唯一选项)
这里比较麻烦的是 这些参数有些是 %aD 这样的 第一次 tab 键显示出来的只是 第一个可选字符,如果你想知道 %a 后面是否可以再填写其他,就在 %a 后 再继续 tab 列出来.
转义字符 | 描述 |
---|---|
%H | commit hash |
%h | 缩短的 commit hash |
%T | tree hash |
%t | 缩短的 tree hash |
%P | parent hashes |
%p | 缩短的 parent hashes |
%an | 作者名字 |
%aN | mailmap 的作者名字 (.mailmap 对应,详情参照git-shortlog(1)或者git-blame(1)) |
%ae | 作者邮箱 |
%aE | 作者邮箱 (.mailmap 对应,详情参照git-shortlog(1)或者git-blame(1)) |
%ad | 日期 (--date= 制定的格式) |
%aD | 日期, RFC2822 格式 |
%ar | 日期, 相对格式 (1 day ago) |
%at | 日期, UNIX timestamp |
%ai | 日期, ISO 8601 格式 |
%cn | 提交者名字 |
%cN | 提交者名字 (.mailmap 对应,详情参照git-shortlog(1)或者git-blame(1)) |
%ce | 提交者 email |
%cE | 提交者 email (.mailmap 对应,详情参照git-shortlog(1)或者git-blame(1)) |
%cd | 提交日期 (--date= 制定的格式) |
%cD | 提交日期, RFC2822 格式 |
%cr | 提交日期, 相对格式 (1 day ago) |
%ct | 提交日期, UNIX timestamp |
%ci | 提交日期, ISO 8601 格式 |
%d | ref 名称 |
%e | encoding |
%s | commit 信息标题 |
%f | sanitized subject line, suitable for a filename |
%b | commit 信息内容 |
%N | commit notes |
%gD | reflog selector, e.g., refs/stash@{1} |
%gd | shortened reflog selector, e.g., stash@{1} |
%gs | reflog subject |
%Cred | 切换到红色 |
%Cgreen | 切换到绿色 |
%Cblue | 切换到蓝色 |
%Creset | 重设颜色 |
%C(...) | 制定颜色, as described in color.branch.* config option |
%m | left, right or boundary mark |
%n | 换行 |
%% | a raw % |
%x00 | print a byte from a hex code |
%w([[,[,]]]) | switch line wrapping, like the -w option of git-shortlog(1) |
-(n):
只显示几条提交
--since,--after:
仅显示指定时间之后的提交.
例如, 最近两周的提交:
格式:
git log --since=2.weeks
--until, --before:
仅显示指定时间之前的提交.
--author:
仅显示指定作者相关的提交.
格式:
git log --author=作者名称
--committer:
仅显示指定提交者相关的提交.
格式:
git log --committer=提交者名称
--grep:
选项搜索提交说明中的关键字。(请注意,如果要得到同时满足这两个选项搜索条件的提交,就必须用--all-match 选项。)
例子格式:
git log --grep=master --grep=feat --all-match
git log -- <path>:
如果只关心某些文件或者目录的历史提交,可以在 git log 选项的最后指定它们的路径。因为是放在最后位置上的选项,所以用两个短划线(--)隔开之前的选项和后面限定的路径名.
例子格式:
git log --stat -- ./js/
--graph:
显示 ASCII 图形表示的分支合并历史
-p:
按补丁格式显示每个更新之间的差异
-stat:
显示每次更新的文件修改统计信息
格式化日期
格式: --date=参数
参数:
参数 | 简写 | 描述 |
---|---|---|
default | show timestamp in the original timezone | |
format | custom format | |
iso-strict | show timestamps in strict ISO 8601 format | |
iso8601 | iso | show timestamps in ISO 8601 format |
local | show timestamps in local timezone | |
raw | show date in internal raw git format(%s %z) | |
relative | show dates relative to the current time | |
rfc2822 | rfc | show timestamps in RFC 2822 format |
short | show only date but not time | |
unix | show date as a Unix epoch timestamp |
1. 正常情况下,输出的是标准时间,但是我们要本地时间可以通过在下面的形式:
格式: --date=参数-local
自定日期格式:
格式: --date=format[-local]:自定义转义字符描述
如何查看到下面的参数,输入下面命令后 git log --date=format:%, 使用 tab 键这个老朋友显示出来(tab键功能,列出可选项,或者直接补充完整唯一选项)
转义字符描述:
转义字符 | 描述 |
---|---|
%a | Abbreviated weekday name |
%A | Full weekday name |
%b | Abbreviated month name |
%B | Full month name |
%c | Date and time representation appropriate for locale |
%d | Day of month as decimal number (01 – 31) |
%H | Hour in 24-hour format (00 – 23) |
%I | Hour in 12-hour format (01 – 12) |
%j | Day of year as decimal number (001 – 366) |
%m | Month as decimal number (01 – 12) |
%M | Minute as decimal number (00 – 59) |
%p | Current locale's A.M./P.M. indicator for 12-hour clock |
%S | Second as decimal number (00 – 59) |
%U | Week of year as decimal number, with Sunday as first day of week (00 – 53) |
%w | Weekday as decimal number (0 – 6; Sunday is 0) |
%W | Week of year as decimal number, with Monday as first day of week (00 – 53) |
%x | Date representation for current locale |
%X | Time representation for current locale |
%y | Year without century, as decimal number (00 – 99) |
%Y | Year with century, as decimal number |
%z, %Z | Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown |
%% | Percent sign |
例如, 2020-01-01 10:00:00.
标准时间格式:
--date=format:'%Y-%m-%d %H:%M:%S'
本地时间格式:
--date=format-local:'%Y-%m-%d %H:%M:%S'
remote 命令:
更新远程分支: git remote update --prune
Other:
git config:
1. `git config`分为3个级别 local, global, system.
2. 配置优先级别 local > global > system.
不同级别的配置存放的地方
Linux/MacOS:
local: .git/config
global: ~/.gitconfig
system: git 的安装目录下的 /etc/gitconfig
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。