Git commands to get information about changes made to your files
Tags: git, vcs, opensource, github
Published: 2022-02-05 17:44:54

Hi,
In this article you will learn git commands which you can use to get information about the changes made to your files. Below is the list of commands that you'll learn in this article. 

- git log
- git log -p
- git show
- git log --stat
- git diff
- git diff --staged

## ``` git log ```

The **_git log_** command shows the list of all commits that have been made in the current git repository. 
Let's see the output when using git log:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frakl34ol2hrcwc8sfmz.png)

In the image above you can see, by default the git log shows the _commit id_, _author_, _date_, and _commit message_.

## ``` git log -p ```

The **_git log_** shows the list of all the commits. But what if you want to see the actual lines changed in each commit? 
So, in this case you can use the **_-p_** flag with **_git log_**. Here **p** comes from patch, because using this flag gives us the patch that was created.
Let's see the output when using **_git log -p_**:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m32lqz5f98favlxni8b4.png)

In the image above you can see that it shows the added lines with plus(+) and removed lines with minus(-), and as the amount of output text is longer than what fits on the screen, git automatically uses a paging tool that allows you to scroll using page up, page down and arrows keys. You can quit the paging tool by entering 'q' from your keyboard. In the output you have one commit below the other and each commit takes up the different space depending on how many lines were added or removed in that commit.

## ``` git show ```

To see the actual lines changed in a specific commit you can use **_git show_** command. The git show command takes the _commit id_ and then shows the files changed in that commit. You can get the commit id of a specific commit by using _git log_. Let say you have a _commit id_: '8a0d3873714c16cb8cc3810fe4861a770892ea97', now you can see the files changed to this commit using:

``` git show 8a0d3873714c16cb8cc3810fe4861a770892ea97 ```

Below is the output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/em77i7ric7ie19fqc407.png)

In the image above you can see that it only showed the patch of that specific commit. The benefit of using git show is that you don't need to scroll to a specific commit in the output of **_git log -p_** to see the files changed. You can directly see the files changed by providing the _commit id_ to _git show_ command.

## ``` git log --stat ```

It is the interesting command that shows the stats about commits such as how many files are changed and how many lines are added or removed.
Lets see the output when using **_git log --stat_**:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkumfhg9tx730nl196mh.png)

In the image above you can see it showed the stats such as the number of files changed and the number of insertions and deletions.

## ``` git diff ```

This command shows the changes made to the files and the output is same as linux **_diff -u_** command. But one point to be noted here is that git diff only shows the **un-staged**(the changes that are not added to the staging area) changes. 
Let's see the output when using git diff:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zsdz9h76u1ag5vh8ida.png)

In the image above you can see that git diff shows the changes made to the file by plus(+) and minus(-) representing the insertions and deletions.

## ``` git diff --staged ```

As I mentioned above **_git diff_** only shows the un-staged changes. So, if you want to see the changed made to the files that are staged you can use **_--staged_** flag with git diff. It will show the changes made to the files present in the staging area.


## Summary

There are plenty of other commands that you can use to get information about changes made. You can always use the [reference documentation](https://git-scm.com/docs) to find out more.
Thanks for reading!