Display last git commit comment

前端 未结 10 642
南旧
南旧 2020-12-02 03:36

Often during a commit ($ git -commit -m \"\"), I wish to read my last comment to remember what progress I have made. Is there an easy way to directly access the

相关标签:
10条回答
  • 2020-12-02 04:03

    You can use

    git show -s --format=%s
    

    Here --format enables various printing options, see documentation here. Specifically, %smeans 'subject'. In addition, -s stands for --no-patch, which suppresses the diff content.

    I often use

    git show -s --format='%h %s'
    

    where %h denotes a short hash of the commit

    Another way is

    git show-branch --no-name HEAD
    

    It seems to run faster than the other way.

    I actually wrote a small tool to see the status of all my repos. You can find it on github.

    0 讨论(0)
  • 2020-12-02 04:08

    For something a little more readable, run this command once:

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

    so that when you then run:

    git lg
    

    you get a nice readout. To show only the last line:

    git lg -1
    

    Solution found here

    0 讨论(0)
  • 2020-12-02 04:09

    I just found out a workaround with shell by retrieving the previous command.

    Press Ctrl-R to bring up reverse search command:

    reverse-i-search

    Then start typing git commit -m, this will add this as search command, and this brings the previous git commit with its message:

    reverse-i-search`git commit -m`: git commit -m "message"
    

    Enter. That's it!

    (tested in Ubuntu shell)

    0 讨论(0)
  • 2020-12-02 04:17

    git log -1 will display the latest commit message or git log -1 --oneline if you only want the sha1 and associated commit message to be displayed.

    0 讨论(0)
  • 2020-12-02 04:20

    git log -1 branch_name will show you the last message from the specified branch (i.e. not necessarily the branch you're currently on).

    0 讨论(0)
  • 2020-12-02 04:27

    Generally:

    git log -n
    

    will show you the last n commit messages

    More elegantly - if you want a quick overview of your commits

    git log --oneline -n
    

    This will Show just the first line of the last n commit messages.

    You can save this as a git alias or a shell alias with a shorter command. I've got it in my shell as glog, for example, and I can see my last 10 commit messages with glog -10.

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