Join Kevin Skoglund for an in-depth discussion in this video Viewing commits, part of Git Essential Training.
In the last movie, we saw how to get more out of the commit log, so any time we're looking at the commit log, we're looking at a list of commits. What if we want to look at a specific commit though? We want to see what changed. What was this commit all about? I want to examine it and see what was committed. Well we do that with git show, so git show followed by a SHA, so let's take a look here at git log --oneline, and get a list of our commits, and then let's show one of them, git show, and let's take a look at this one here, moved sunglasses higher in list of suggested outdoor items.
So I just paste the SHA right there and then hit Return. It shows me the full SHA for the commit, it shows me the author of the date, the commit message and then gives me a diff of the commit. Remember we saw diffs before when we were trying to see what had changed before we decided what content we wanted to commit. We could diff the two to see what changed. Well, here it's showing us what was committed, the diff between what was there before and what was there after. So sunglasses was added in this spot, and it was removed in this spot. That's what the change was, and it gives me the plus and the minus as well as some coloring to indicate the changes.
I can hit space to make sure that there is nothing else after it, and then Q to quit out of it. So that's it, that's what a show looks like. Let's take a look again in our log, let's take a look at different one, let's say this one where we add a file. Let's see what that looks like, git show, and that SHA, and there it is. It's adding a file, so diff is /dev/null which is computer speak for empty, so it didn't exist before, and now here it is. So compared to nothing, it's all added, all these items are added here, all new.
Same thing if we delete something, it'll of course all be removed, it'll show them all as being minuses. Now that you can also pass in formats here, mainly it has to do with what the format looks like at the top, so let's say format=, and we can have oneline and then let's give it our SHA, I'll just say HEAD, so there is what our HEAD looks like. Let's take a look at HEAD back one, there is the one that's before that, and let's do HEAD back two, or HEAD~3, that shows us the commit that was before that, so we can surf around and go back and look at these commits.
There are some other options you can pass in. You can look through the help documents to find those. Now what we're passing into it is a tree-ish object like before, but git show actually does handle them all a little differently. If we do the help docs git help show, you'll see it takes blobs, trees, tags and commits, so we're mostly working with commits here. If we passed in a tree, it would show the names of what was in the tree, it's equivalent to doing git ls-tree with the name-only option, so it's the exact same thing.
For plain blobs, that's files, it shows the contents. Let me just demonstrate both of those real quick. So let's do git ls-tree master, so there is our list. Here is the one for assets, so I'm just going to grab the first part of that and tell it git show that tree. That's the tree that we want to focus on, that's the tree-ish object we're passing in, it comes up and gives me a list of what's inside there. Again this is same as git ls- tree with the name-only option. Let's do the same thing for our file.
We have our index file here, again, we pass in the tree-ish object, git show, and then we pass in that SHA, and there it is, there's the content. Now I just want to point out that that's not the same thing as saying git show index.html. That's not a tree-ish. We can't pass that in. That is not a reference that it understands as a tree-ish object, so it comes up and it says I don't know what that is. We have to pass in the SHA or some other reference to the file that it can understand a tree-ish.
So I think between viewing the tree, viewing a log file, and viewing the commits, you'll be able to navigate around and really see what's been committed to the repository before. The last thing that's super useful is being able to compare commits, and that's what we'll do in the next movie.
- Exploring the history of version control
- Installing Git on Mac, Windows, and Linux
- Initializing a repository
- Writing useful commit messages
- Understanding the Git three-tree architecture
- Tracking when files are added, edited, deleted, or moved
- Viewing change sets and comparing versions
- Undoing changes and rolling back to previous versions
- Ignoring changes to select files
- Creating and working with code branches
- Merging branches and resolving merge conflicts
- Stashing changes for later
- Working with hosted repositories and remote branches
- Developing an effective collaboration workflow
Skill Level Beginner
Q: In the Chapter 10 movie "Configuring the command prompt to show the branch," when I type the function "__git_ps1," I do not get the expected result.
A: The function "__git_ps1" was recently moved to a new file, .git-prompt.sh, as described here: https://github.com/git/git/commit/af31a456b4cd38f2630ed8e556e23954f806a3cc.
We will update the video. In the meantime, you may do the same steps you do for .git-completion.bash, but a second time using ".git-prompt.sh" as shown here: https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh.
Q: When I use the code the instructor advises in the above video ("git config --global user.name "Nelda Street"), I still get an "Illegal Instruction" error. I have OS 10.6.8. Am I doing something wrong?
A: The current installer version of git isn't compatible with older Mac OS versions.
1. To add "-mmacosx-version-min=10.6" as described here:https://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10https://stackoverflow.com/questions/10177038/illegal-instruction-4-shows-up-in-os-x-lion
2. Or to use the version of git that comes with Xcode, or to use homebrew to install git instead.http://superuser.com/questions/697144/installed-git-not-sure-how-to-get-it-working