美文网首页
Git 常用命令总结之查看 commit 提交日志常用参数

Git 常用命令总结之查看 commit 提交日志常用参数

作者: AndyGF | 来源:发表于2020-05-21 15:14 被阅读0次

    在终端中我们经常需要查看代码版本历史演变过程, 此时就需要用到 git log 这个命令.
    常用的 log 命令有以下几个(单独使用情况)

    $ git log
    $ git log --oneline
    $ git log -n2
    $ git log 分支名称
    $ git log --all
    $ git log --graph
    

    单独使用

    1. 不加任何参数, 展示的是当前分支 commit id 编号, 作者, email, 日期, 变更的内容
    $ git log
    
    1. 后面加上 --oneline 参数, 只展示 commit id 编号的部分和变更的内容,
    $ git log --oneline
    
    1. 只看最近的 2 次提交,
    $ git log -n2
    
    1. 只查看某个分支的 log
    $ git log 分支名称
    
    1. 查看所有分支 commit 信息
    $ git log --all
    
    1. 图形化(树形结构)展示 log,
    $ git log --graph
    

    组合使用, 可以根据自己实际情况自行组合:

    • 查看 4 条单行 log,
    $ git log -n4 --oneline
    
    • 查看所有分支最近 10 条 log,
    $ git log -n10 --all
    

    更多 log 参数, 请移步 Git 官网查看

    Git 官网 log 参数使用说明

    补充命令

    • 创建分支
    $ git checkout -b new_branch_name  base_commit_id
    
    • 查看本地有多少分支
    $ git branch -v
    
    • 查看所有分支, 包括远端分支
    $ git branch -av
    
    • 用 git 重命名文件
    $ git  mv  原名  新名
    
    • 将所有变更的文件添加到暂存区
    $  git add -u
    

    或者 (注意 add 后边有个 '点')

    $  git add .
    
    • 清空暂存区, 这个命令比较危险, 慎用!!!
    $ git reset --hard
    
    • 直接将改动添加到暂存区并提交 commit
    $ git commit -am '改动事项说明'
    
    • 查看代码仓库的提交者统计
      来自 @六个周
    $ git shortlog -sn
    

    相关文章

      网友评论

          本文标题:Git 常用命令总结之查看 commit 提交日志常用参数

          本文链接:https://www.haomeiwen.com/subject/hedzohtx.html