Display A Repos's Commits

1. when Return a repo, Check status

1
$ git status

2. Display commits

1
$ git log

Display the SHA, Auother, Date, and content

Navigating in Less)

  • to scroll down, press

    • j or to move down one line at a time
    • d to move by half the page screen
    • f to move by a whole page screen
  • to scroll up, press

    • k or to move up one line at a time
    • u to move by half the page screen
    • b to move by a whole page screen
  • press q to quit out of the log

    (returns to the regular command prompt)

Search commits by message

EX: Message Set article timestamp color

1
$ git log --grep='Set article timestamp color'

OUTPUT:

1
2
3
4
5
commit 5de135ab4ca51b7d86b53ea1f81bca100c6eeb40
Author: Richard Kalehoff <richardkalehoff@gmail.com>
Date: Sat Dec 3 15:42:07 2016 -0500

Set article timestamp color

Display commits in oneline

1
$ git log --oneline

This command:

  • lists one commit per line
  • shows the first 7 characters of the commit’s SHA
  • shows the commit’s message

OUTPUT

1
2
3
4
5
6f04ddd Add breakpoint for large-sized screens
50d835d Add breakpoint for medium-sized screens
0768f3d Add space around page edge
f9720a9 Style page header
...

git log --stat Recap

--stat is a flag

To recap, the --stat flag is used to alter how git log displays information:

1
$ git log --stat
1
$ git log 8d3ea36  --stat

This command:

  • displays the file(s) that have been modified
  • displays the number of lines that have been added/removed
  • displays a summary line with the total number of modified files and lines that have been added/removed

git log -p Recap

To recap, the -p flag (which is the same as the --patch flag) is used to alter how git log displays information:

1
$ git log -p

This command adds the following to the default output:

  • displays the files that have been modified
  • displays the location of the lines that have been added/removed
  • displays the actual changes that have been made
1
$ git log -p -w

With-w, don’t highlight lines where only whitespace changes occurred.

Annotated git log -p Output

git log -p or git log --patch

img

Using the image above, let’s do a quick recap of the git log -p output:

  • 🔵 - the file that is being displayed
  • 🔶 - the hash of the first version of the file and the hash of the second version of the file not usually important, so it’s safe to ignore
  • ❤️ - the old version and current version of the file
  • 🔍 - the lines where the file is added and how many lines there are
    • -15,83 indicates that the old version (represented by the -) started at line 15 and that the file had 83 lines
    • +15,85 indicates that the current version (represented by the +) starts at line 15 and that there are now 85 lines…these 85 lines are shown in the patch below
  • ✏️ - the actual changes made in the commit
    • lines that are red and start with a minus (-) were in the original version of the file but have been removed by the commit
    • lines that are green and start with a plus (+) are new lines that have been added in the commit

git show

git show can be combined with most of the other flags we’ve looked at:

  • --stat - to show the how many files were changed and the number of lines that were added/removed
  • -p or --patch - this the default, but if --stat is used, the patch won’t display, so pass -p to add it again
  • -w - to ignore changes to whitespace