zoukankan      html  css  js  c++  java
  • git log 查看提交记录

    git log 查看提交记录

    1. git log 查看提交历史记录
    2. git log --oneline 或者 git log --pretty=oneline 以精简模式显示
    3. git log --graph 以图形模式显示
    4. git log --stat 显示文件更改列表
    5. git log --author= 'name' 显示某个作者的日志
    6. git log -p filepath 查看某个文件的详细修改
    7. git log -L start,end:filepath 查看某个文件某几行范围内的修改记录
    8. git log --stat commitId 或者 git show --stat commitId 查看某一次提交的文件修改列表

    git diff 文件对比
    1. git diff filepath 工作区与暂存区比较
    2. git diff HEAD filepath 工作区与HEAD ( 当前工作分支) 比较
    3. git diff --staged 或 --cached filepath 暂存区与HEAD比较
    4. git diff branchName filepath 当前分支的文件与branchName 分支的文件进行比较
    5. git diff commitId filepath 与某一次提交进行比较

    git log 有两个高级用法:一是自定义提交的输出格式,二是过滤输出哪些提交.

    格式化 Log 输出

    #只显示提交ID和提交信息的第一行
    git log --oneline
    
    #知道每个提交关联的分支或者标签
    git log --oneline --decorate
    

    Diff

    文件名后面 + 和 - 的数量是这个提交造成的更改中增删的相对比例.

    #--stat 选项显示每次提交的文件增删数量
    git log --stat
    # -p 如果你想知道每次提交删改的绝对数量
    git log -p

    Shortlog

    #它把每个提交按作者分类,显示提交信息的第一行。这样可以容易地看到谁做了什么。
    git shortlog

    默认情况下,git shortlog 把输出按作者名字排序,但你可以传入 -n 选项来按每个作者提交数量排序。

    Graph

    #--graph 选项绘制一个 ASCII 图像来展示提交历史的分支结构
    #星号表明这个提交所在的分支
    git log --graph --oneline --decorate

    按内容

    #当你想要知道 Hello, World! 字符串是什么时候加到项目中哪个文件中去的
    git log -S "Hello, World!"

    按范围

    #master..feature 范围包含了在 feature 分支而不在 master 分支中所有的提交
    git log master..feature
    git log用于查询版本的历史,命令形式如下:
    git log [<options>] [<since>..<until>] [[--] <path>...]
    这条命令有很多参数选项
    一、不带参数
    1. 如果不带任何参数,它会列出所有历史记录,最近的排在最上方,显示提交对象的哈希值,作者、提交日期、和提交说明
    2. 如果记录过多,则按Page Up、Page Down、↓、↑来控制显示
    3. 按q退出历史记录列表
     
    二、显示参数
    1. -p:按补丁显示每个更新间的差异,比下一条- -stat命令信息更全
    2. --stat:显示每次更新的修改文件的统计信息,每个提交都列出了修改过的文件,以及其中添加和移除的行数,并在最后列出所有增减行数小计
    3. --shortstat:只显示--stat中最后的行数添加修改删除统计
    4. --name-only:尽在已修改的提交信息后显示文件清单
    5. --name-status:显示新增、修改和删除的文件清单
    6. --abbrev-commit:仅显示SHA-1的前几个字符,而非所有的40个字符
    7. --relative-date:使用较短的相对时间显示(例如:"two weeks ago")
    8. --graph:显示ASCII图形表示的分支合并历史
    9. —pretty=:使用其他格式显示历史提交信息,可选项有:oneline,short,medium,full,fuller,email,raw以及format:<string>,默认为medium,如:
      1. --pretty=oneline:一行显示,只显示哈希值和提交说明(--online本身也可以作为单独的属性)
      2. --pretty=format:” ":控制显示的记录格式,如:
        1. %H  提交对象(commit)的完整哈希字串
        2. %h  提交对象的简短哈希字串
        3. %T  树对象(tree)的完整哈希字串
        4. %t  树对象的简短哈希字串
        5. %P  父对象(parent)的完整哈希字串
        6. %p  父对象的简短哈希字串
        7. %an 作者(author)的名字
        8. %ae 作者的电子邮件地址
        9. %ad 作者修订日期(可以用 -date= 选项定制格式)
        10. %ar 作者修订日期,按多久以前的方式显示
        11. %cn 提交者(committer)的名字
          1. 作者和提交者的区别不知道是啥?
          2. 作者与提交者的关系:作者是程序的修改者,提交者是代码提交人(自己的修改不提交是怎么能让别人拉下来再提交的?)
          3. 其实作者指的是实际作出修改的人,提交者指的是最后将此工作成果提交到仓库的人。所以,当你为某个项目发布补丁,然后某个核心成员将你的补丁并入项目时,你就是作者,而那个核心成员就是提交者(soga)
        12. %ce 提交者的电子邮件地址
        13. %cd 提交日期(可以用 -date= 选项定制格式)
        14. %cr 提交日期,按多久以前的方式显示
        15. %s  提交说明
      3. 带颜色的--pretty=format:” ",这个另外写出来分析
        1. 以这句为例:%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>
        2. 它的效果是:   
        3. 先断句:[%Cred%h][%Creset   -][%C(yellow)%d ][%Cblue%s][%Cgreen(%cd)][%C(bold blue)<%an>]
        4. 然后就是很明显能得到的规律了
          1. 一个颜色+一个内容
          2. 颜色以%C开头,后边接几种颜色,还可以设置字体,如果要设置字体的话,要一块加个括号
            1. 能设置的颜色值包括:reset(默认的灰色),normal, black, red, green, yellow, blue, magenta, cyan, white.
            2. 字体属性则有bold, dim, ul, blink, reverse.  
          3. 内容可以是占位元字符,也可以是直接显示的普通字符
    10. --date= (relative|local|default|iso|rfc|short|raw):定制后边如果出现%ad或%cd时的日期格式
      1. 有几个默认选项
        1. --date=relative:shows dates relative to the current time, e.g. "2 hours ago".
        2. --date=local:shows timestamps in user’s local timezone.
        3. --date=iso (or --date=iso8601):shows timestamps in ISO 8601 format.
        4. --date=rfc (or --date=rfc2822):shows timestamps in RFC 2822 format,often found in E-mail messages.
        5. --date=short:shows only date but not time, in YYYY-MM-DD format.这个挺好用
        6. --date=raw:shows the date in the internal raw git format %s %z format.
        7. --date=default:shows timestamps in the original timezone (either committer’s or author’s).
      2. 也可以自定义格式(需要git版本2.6.0以上),比如--date=format:'%Y-%m-%d %H:%M:%S' 会格式化成:2016-01-13 11:32:13,其他的格式化占位符如下:
        1. %a:Abbreviated weekday name
        2. %A:Full weekday name
        3. %b:Abbreviated month name
        4. %B:Full month name
        5. %c:Date and time representation appropriate for locale
        6. %d:Day of month as decimal number (01 – 31)
        7. %H: Hour in 24-hour format (00 – 23)
        8. %I:Hour in 12-hour format (01 – 12)
        9. %j:Day of year as decimal number (001 – 366)
        10. %m:Month as decimal number (01 – 12)
        11. %M:Minute as decimal number (00 – 59)
        12. %p:Current locale's A.M./P.M. indicator for 12-hour clock
        13. %S:Second as decimal number (00 – 59)
        14. %U:Week of year as decimal number, with Sunday as first day of week (00 – 53)
        15. %w:Weekday as decimal number (0 – 6; Sunday is 0)
        16. %W:Week of year as decimal number, with Monday as first day of week (00 – 53)
        17. %x:Date representation for current locale
        18. %X:Time representation for current locale
        19. %y:Year without century, as decimal number (00 – 99)
        20. %Y:Year with century, as decimal number
        21. %z, %Z:Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
        22. %%:Percent sign
     
    三、筛选参数:
    1. 按数量
      1. -n:显示前n条log
    2. 按日期
      1. --after=
        1. 比如git log --after="2014-7-1”,显示2014年7月1号之后的commit(包含7月1号)
        2. 后边的日期还可以用相对时间表示,比如"1 week ago"和”yesterday",比如git log --after="yesterday"
        3. 这里的格式可以是什么?
      2. --before=
        1. 同上
        2. 另外这两条命令可以同时使用表示时间段,比如git log --after="2014-7-1" --before="2014-7-4"
        3. 另外--since --until和 --after --before是一个意思,都可以用
    3. 按作者
      1. --author=
        1. 比如git log --author=“John",显示John贡献的commit
        2. 注意:作者名不需要精确匹配,只需要包含就行了
        3. 而且:可以使用正则表达式,比如git log --author="John|Mary”,搜索Marry和John贡献的commit
        4. 而且:这个--author不仅包含名还包含email, 所以你可以用这个搜索email
    4. 按commit描述
      1. --grep=
        1. 比如:git log --grep="JRA-224"
        2. 而且:可以传入-i用来忽略大小写
        3. 注意:如果想同时使用--grep和--author,必须在附加一个--all-match参数
    5. 按文件
      1. - -(空格)或[没有]
        1. 有时你可能只对某个文件的修改感兴趣, 你只想查看跟某个文件相关的历史信息, 你只需要插入你感兴趣文件的路径[对,是路径,所以经常是不太好用]就可以了
        2. 比如:git log -- foo.py bar.py ,只返回和foo.py或bar.py相关的commit
        3. 这里的--是告诉Git后面的参数是文件路径而不是branch的名字. 如果后面的文件路径不会和某个branch产生混淆, 你可以省略- -,比如git log foo.py 
        4. 另外,后边的路径还支持正则,比如:git log  *install.md 是,指定项目路径下的所有以install.md结尾的文件的提交历史
        5. 另外,文件名应该放到参数的最后位置,通常在前面加上--并用空格隔开表示是文件
        6. 另外,git log file/ 查看file文件夹下所有文件的提交记录
    6. 按分支
      1. - -
        1. --branchName branchName为任意一个分支名字,查看某个分支上的提交记录
        2. 需要放到参数中的最后位置处
        3. 如果分支名与文件名相同,系统会提示错 误,可通过--选项来指定给定的参数是分支名还是文件名
          1. 比如:在当前分支中有一个名为v1的文件,同时还存在一个名为v1的分支
          2. git log v1 -- 此时的v1代表的是分支名字(--后边是空的)
          3. git log -- v1 此时的v1代表的是名为v1的文件
          4. git log v1 -- v1 代表v1分支下的v1文件
    7. 按内容
      1. -S"<string>"、-G"<string>"
        1. 有时你想搜索和新增或删除某行代码相关的commit. 可以使用这条命令
        2. 假设你想知道Hello, World!这句话是什么时候加入到项目里去的,可以用:git log -S"Hello,World!"
        3. 另外:如果你想使用正则表达式去匹配而不是字符串, 那么你可以使用-G代替-S.
        4. 这是一个非常有用的debug工具, 使用他你可以定位所有跟某行代码相关的commit. 甚至可以查看某行是什么时候被copy的, 什么时候移到另外一个文件中去的
        5. 注:-S后没有"=",与查询内容之间也没有空格符
    8. 按范围
      1. git log <since>..<until>
        1. 这个命令可以查看某个范围的commit
        2. 这个命令非常有用当你使用branch做为range参数的时候. 能很方便的显示2个branch之间的不同
        3. 比如:git log master..feature,master..feature这个range包含了在feature有而在master没有的所有commit,同样,如果是feature..master包含所有master有但是feature没有的commit
        4. 另外,如果是三个点,表示或的意思:git log master...test 查询master或test分支中的提交记录
    9. 过滤掉merge commit
      1. --no-merges
        1. 默认情况下git log会输出merge commit.  你可以通过--no-merges标记来过滤掉merge commit,git log --no-merges
        2. 另外,如果你只对merge commit感兴趣可以使用—merges,git log --merges
    10. 按标签tag
      1. git log v1.0
        1. 直接这样是查询标签之前的commit
        2. 加两个点git log v1.0.. 查询从v1.0以后的提交历史记录(不包含v1.0)
    11. 按commit
      1. git log commit :查询commit之前的记录,包含commit
      2. git log commit1 commit2:查询commit1与commit2之间的记录,包括commit1和commit2
      3. git log commit1..commit2:同上,但是不包括commit1
        1. 其中,commit可以是提交哈希值的简写模式,也可以使用HEAD代替
          1. HEAD代表最后一次提交,HEAD^为最后一个提交的父提交,等同于HEAD~1
          2. HEAD~2代表倒数第二次提交

    =========================== End

  • 相关阅读:
    C++中整型变量的存储大小和范围
    A1038 Recover the Smallest Number (30 分)
    A1067 Sort with Swap(0, i) (25 分)
    A1037 Magic Coupon (25 分)
    A1033 To Fill or Not to Fill (25 分)
    A1070 Mooncake (25 分)
    js 获取控件
    C#代码对SQL数据库添加表或者视图
    JS 动态操作表格
    jQuery取得下拉框选择的文本与值
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/9485874.html
Copyright © 2011-2022 走看看