Course Content
Git Essentials
Git Essentials
Viewing Changes
git log -p
We have already discussed how to view our commit history using the git log
command. However, it is often the case when we may also want to see the exact lines changed in each commit. Such an approach is useful when we want to quickly find a commit which introduces a certain bug to our program.
That’s where the git log
command with the -p
(stands for patch) flag comes in handy. Here is the full command:
Let’s now run it in the terminal:
I separated each commit with a frame of different colors to enhance visual distinguishability. Since we have detailed information about each commit, all text doesn't fit on the screen, so you can use the arrow keys to scroll up and down.
Note
You can exit pressing the q key.
Here, plusses show added lines, and if we had deleted some lines, they would be shown with minuses (dashes).
git show
The primary purpose of git show
is to provide a detailed view of the changes introduced by a particular commit. Here's a basic syntax for the git show
command:
Where [commit] is the identifier (hash) of the commit you want to display.
Let’s take a look at the output of the git log -p
command, specifically focusing on the second latest commit:
Here are the first few lines of the output for this commit. To use the git show
command for this commit, copy its hash and run the following command:
Note
Your commit hash may be different, so be sure to use the correct hash.
Let’s run this command in the terminal:
As you can see, the output is the same as for the git log -p
command, but only for one commit.
Thanks for your feedback!