关于git:git-命令行的使用

3次阅读

共计 3539 个字符,预计需要花费 9 分钟才能阅读完成。

根底命令:

查看版本: git –version

log 命令:

git log: 显示 commit 记录

log 参数:

–pretty:

 输入 log 的格局.
–pretty 参数:
参数 形容
email 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

正文完
 0