Getting Git

A comprehensive video course from git init to Git Master.

Master: git show

In this video we'll learn some of the additional options for git show.

We can limit the output of git show to simply list the files that changed as part of the commit with --name-status.

This option can also be used with git log.

We can see --name-status lists each file changed as well as how it was changed.

In this case, it shows File 2 was M for modified. There's also A for added, D for deleted, and a few others which are less common.

At times, you will want to view a file at a previous point in history or on another branch.

We can use git show to do this by passing a reference to a commit followed by the filename.

For example, to output the contents of File 2 two commits ago, I would run:

git show HEAD~2:file-2.txt

The reference doesn't have to be relative. It could be the commit SHA, or a branch name as we'll see in Part 3.

Now, when I run this command I receive an error. If we read the message it says File 2 was not in HEAD~2.

This means while File 2 existed, it wasn't tracked by the Git repository at this point in time.

If we run git log --oneline we see two commits ago was my Initial commit. But I didn't add File 2 until the next commit.

So this error is expected and is a good example of both slowing down to read the output Git commands as well as using git show and git log together.

Part of mastering Git will be knowing which command to use. Often, there are multiple ways to do the same thing.

So use git show to view information about a single commit. For everything else, use git log.