git 命令行的使用
码农天地 -基础命令:
查看版本: git --version
log命令:git log: 显示 commit 记录
log参数:--pretty:输出 log 的格式.
--pretty参数:参数描述emailuse email headers like From and Subjectformatspecify own formatfullall parts of commit messagesfullerlike full and includes datesmediummost parts of messagesonelinecommit-ids and subject of messagesrawthe raw commitsshortfew headers and only subject of messagespretty 自定义格式转义字符: 如何查看到下面的参数,输入下面命令后 git log --pretty=format:%, 使用 tab 键这个老朋友显示出来(tab键功能,列出可选项,或者直接补充完整唯一选项)
这里比较麻烦的是 这些参数有些是 %aD 这样的 第一次 tab 键显示出来的只是 第一个可选字符,如果你想知道 %a 后面是否可以再填写其他,就在 %a 后 再继续 tab 列出来.
只显示几条提交
--since,--after:仅显示指定时间之后的提交.
例如, 最近两周的提交:
格式:
git log --since=2.weeks
仅显示指定时间之前的提交.
仅显示指定作者相关的提交.
格式:
git log --author=作者名称
仅显示指定提交者相关的提交.
格式:
git log --committer=提交者名称
选项搜索提交说明中的关键字。(请注意,如果要得到同时满足这两个选项搜索条件的提交,就必须用--all-match 选项。)
例子格式:
git log --grep=master --grep=feat --all-match
如果只关心某些文件或者目录的历史提交,可以在 git log 选项的最后指定它们的路径。因为是放在最后位置上的选项,所以用两个短划线(--)隔开之前的选项和后面限定的路径名.
例子格式:
git log --stat -- ./js/
显示 ASCII 图形表示的分支合并历史
-p:按补丁格式显示每个更新之间的差异
-stat:显示每次更新的文件修改统计信息
格式化日期格式: --date=参数
参数:参数简写描述default show timestamp in the original timezoneformat custom formatiso-strict show timestamps in strict ISO 8601 formatiso8601isoshow timestamps in ISO 8601 formatlocal show timestamps in local timezoneraw show date in internal raw git format(%s %z)relative show dates relative to the current timerfc2822rfcshow timestamps in RFC 2822 formatshort show only date but not timeunix show date as a Unix epoch timestamp 1. 正常情况下,输出的是标准时间,但是我们要本地时间可以通过在下面的形式:
格式: --date=参数-local
格式: --date=format[-local]:自定义转义字符描述
如何查看到下面的参数,输入下面命令后 git log --date=format:%, 使用 tab 键这个老朋友显示出来(tab键功能,列出可选项,或者直接补充完整唯一选项)
转义字符描述:
转义字符描述%aAbbreviated weekday name%AFull weekday name%bAbbreviated month name%BFull month name%cDate and time representation appropriate for locale%dDay of month as decimal number (01 – 31)%HHour in 24-hour format (00 – 23)%IHour in 12-hour format (01 – 12)%jDay of year as decimal number (001 – 366)%mMonth as decimal number (01 – 12)%MMinute as decimal number (00 – 59)%pCurrent locale's A.M./P.M. indicator for 12-hour clock%SSecond as decimal number (00 – 59)%UWeek of year as decimal number, with Sunday as first day of week (00 – 53)%wWeekday as decimal number (0 – 6; Sunday is 0)%WWeek of year as decimal number, with Monday as first day of week (00 – 53)%xDate representation for current locale%XTime representation for current locale%yYear without century, as decimal number (00 – 99)%YYear with century, as decimal number%z, %ZEither 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'
更新远程分支: git remote update --prune