基础命令:

查看版本: git --version

log命令:

git log: 显示 commit 记录

log参数:

--pretty:

输出 log 的格式.
--pretty参数:
参数描述
emailuse email headers like From and Subject
formatspecify own format
fullall parts of commit messages
fullerlike full and includes dates
mediummost parts of messages
onelinecommit-ids and subject of messages
rawthe raw commits
shortfew headers and only subject of messages
pretty 自定义格式转义字符:

  如何查看到下面的参数,输入下面命令后 git log --pretty=format:%, 使用 tab 键这个老朋友显示出来(tab键功能,列出可选项,或者直接补充完整唯一选项)
  这里比较麻烦的是 这些参数有些是 %aD 这样的 第一次 tab 键显示出来的只是 第一个可选字符,如果你想知道 %a 后面是否可以再填写其他,就在 %a 后 再继续 tab 列出来.

转义字符描述
%Hcommit hash
%h缩短的 commit hash
%Ttree hash
%t缩短的 tree hash
%Pparent hashes
%p缩短的 parent hashes
%an作者名字
%aNmailmap 的作者名字 (.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 格式
%dref 名称
%eencoding
%scommit 信息标题
%fsanitized subject line, suitable for a filename
%bcommit 信息内容
%Ncommit notes
%gDreflog selector, e.g., refs/stash@{1}
%gdshortened reflog selector, e.g., stash@{1}
%gsreflog subject
%Cred切换到红色
%Cgreen切换到绿色
%Cblue切换到蓝色
%Creset重设颜色
%C(...)制定颜色, as described in color.branch.* config option
%mleft, right or boundary mark
%n换行
%%a raw %
%x00print 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
iso8601isoshow 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
rfc2822rfcshow 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键功能,列出可选项,或者直接补充完整唯一选项)

转义字符描述:

转义字符描述
%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'

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

_xk
30 声望2 粉丝

要么吊, 要么掉.