How to output git log with the first line only?

前端 未结 9 1829
猫巷女王i
猫巷女王i 2021-01-29 17:29

I am trying to customize the format for git log. I want all commits to be shown in one line. Each line should only show the first line of the commit message.
I

相关标签:
9条回答
  • 2021-01-29 17:55

    if you only want the first line of the messages (the subject):

    git log --pretty=format:"%s"
    

    and if you want all the messages on this branch going back to master:

    git log --pretty=format:"%s" master..HEAD
    

    Last but not least, if you want to add little bullets for quick markdown release notes:

    git log --pretty=format:"- %s" master..HEAD
    
    0 讨论(0)
  • 2021-01-29 17:58

    Better and easier git log by making an alias. Paste the code below to terminal just once for one session. Paste the code to zshrc or bash profile to make it persistant.

    git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
    

    Output

    git lg
    

    Output changed lines

    git lg -p
    

    Alternatively (recommended)
    Paste this code to global .gitconfig file

    [alias]
      lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    

    Further Reading.
    https://coderwall.com/p/euwpig/a-better-git-log
    Advanced Reading.
    http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/

    0 讨论(0)
  • 2021-01-29 18:05

    If you don't want hashes and just the first lines (subject lines):

    git log --pretty=format:%s
    
    0 讨论(0)
  • 2021-01-29 18:07

    Without commit messages, only the hash:

    git log --pretty=oneline | awk '{print $1}'
    
    0 讨论(0)
  • 2021-01-29 18:07

    if you want to always use git log in such way you could add git alias by

    git config --global alias.log log --oneline

    after that git log will print what normally would be printed by git log --oneline

    0 讨论(0)
  • 2021-01-29 18:08

    You can define a global alias so you can invoke a short log in a more comfortable way:

    git config --global alias.slog "log --pretty=oneline --abbrev-commit"

    Then you can call it using git slog (it even works with autocompletion if you have it enabled).

    0 讨论(0)
提交回复
热议问题