30 Viewing the Log

Git’s bread and butter is tracking changes to files in your project over a period of time. You use the log to view that history.

You can use git log to view the standard log output. Git displays the commit ID, author, date, and commit message for each commit in reverse chronological order. Git sends the output through less to keep the output from scrolling past on the screen too fast to be seen.

You can use the --oneline parameter to shorten the log display to show the first seven characters of the commit ID and the subject of the log message. It increases the number of commits you can view on one screen and with properly written log messages makes scanning easier.

Viewing the entire history often gives you too much information. You can limit the number of commits git log shows by providing it with -N, changing N with the number of commits you want to display.

Often you need to see the changes made to the file in addition to the log message to fully understand the change. You can use the -p to show the diff the commit made.

What To Do...
  • View a reverse chronological list of all commits.
     
    prompt>​ git log
     
    commit 3ac20cfb09212f212a2f60a6227610c680e8a95e
     
    Author: Travis Swicegood <[email protected]>
     
    Date: Wed Aug 18 09:29:38 2010 -0500
     
     
    add sample output for Part V
     
     
    commit fa0016322bf4e73d1419ddc91777368db0f35484
     
    Author: Travis Swicegood <[email protected]>
     
    Date: Wed Aug 18 09:12:35 2010 -0500
     
     
    add in sample output for Part IV
     
     
    ...​ and so on, and so on ...
  • View the log with one shortened commit ID and subject.
     
    prompt>​ git log --oneline
     
    3ac20cf add sample output for Part V
     
    fa00163 add in sample output for Part IV
     
    8bd724b add note about empty prompt> to the intro
     
    ...​ and so on, and so on ...
  • View the last N commits.
     
    prompt>​ git log -N
     
    ...​ examples ...
     
    prompt>​ git log -5 ​​# show the last five
     
    prompt>​ git log HEAD^^^^^..HEAD ​​# show the last five
     
    prompt>​ git log -10 ​​# show the last ten
     
    prompt>​ git log HEAD~10..HEAD ​​# show the last ten
  • Show the changes made in the latest commit.
     
    prompt>​ git log -1 -p HEAD

    Note that it is a 1 (as in the number) and not an l (as in library).

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.36.38