Viewing A Specific Commit

Too Much Scrolling

The last few quizzes in the previous section had you scrolling and scrolling through the patch output just to get to the right commit so you could see_its_info. Wouldn't it be super handy if you could just display a specific commit's details without worrying about all of the others in the repo?

There are actually two ways to do this!

  • providing the SHA of the commit you want to see to git log
  • use a new command git show

They're both pretty simple, but let's look at thegit logway and then we'll look atgit show.

You already know how to "log" information with:

  • git log
  • git log --oneline
  • git log --stat
  • git log -p

But did you know, you can supply the SHA of a commit as the final argument for all of these commands? For example:

$ git log  -p fdf5493

By supplying a SHA, thegit log -pcommand will start at that commit! No need to scroll through everything! Keep in mind that it will_also_show all of the commits that were made_prior_to the supplied SHA.

New Command:git show

The other command that shows a specific commit isgit show:

$ git show

Running it like the example above will only display the most recent commit. Typically, a SHA is provided as a final argument:

$ git show fdf5493

What doesgit showdo?

Thegit showcommand will showonly one commit. So don't get alarmed when you can't find any other commits - it only shows one. The output of thegit showcommand is exactly the same as thegit log -pcommand. So by default,git showdisplays:

  • the commit
  • the author
  • the date
  • the commit message
  • the patch information

However,git showcan 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

You are now among thegit logging elite! Try your hand at a few quizzes.

QUESTION 1 OF 3

How many rulesets are added to the CSS by commit8d3ea36?

  • 1

  • 2

  • 3

  • 4

SUBMIT

QUESTION 2 OF 3

There's a commit with the message "Convert social links from text to images". How many files were changed by this commit?

  • 2 files

  • 4 files

  • 5 files

  • 9 files

SUBMIT

QUESTION 3 OF 3

Look at commitfdf5493. What's the first HTML heading element that's added by this commit?

  • an<h1>

  • an<h2>

  • an<h3>

  • an<h4>

SUBMIT

results matching ""

    No results matching ""