Git

How to Use git-whatchanged?

In Git bash, committing changes is essential for the users in order to save the modification time, date, and person who commits the changes. For doing this, the “git commit” command is used. In order to view these commits in Git bash, the “git whatchanged” command is examined.

The outcomes of this post are:

How to Use the “git-whatchanged” Command?

The “git whatchanged” command performs the same as a “git-log” command. However, default to the skip merges and view the raw format diff output. It can be kept primarily for historic context. For using the “git whatchanged” command, the following syntax is utilized.

Syntax

The general syntax of the above-described command is stated below:

git whatchanged <option>

 

Let’s move ahead and implement some examples to use the “git whatchanged” command.

Example 1: Display All Commits

To display all commits in the current branch, use the “git whatchanged” command without any option:

git whatchanged

 

The output shows that the two commits changes have been made by the author named “Mateen900” on the given particular date and time:

Example 2: Display the Difference Between Previous and New Commits

The “git whatchanged” command can be used with the “-p” flag to display the difference between previous and new commits. So, let’s check its practical implementation, make some changes, and commits in the file. Then, check the difference between previous and new commits. Have a look at the following instructions:

git whatchanged -p

 

Until now, there are no changes made to the “file.txt” present in the current directory.

Use the “start” command, enter the file name, and modify the file:

start file.txt

 

After that, check the file’s status using the command stated below:

git status

 

As you can see, the content of the “file.txt” has been modified but not committed:

Add the modified file content to the tracking area by using the “git add .” command:

git add .

 

The file has been tracked successfully.

Now, commit changes to the repository and use the “-m” flag for adding the commit message:

git commit -m "updated file"

 

Let’s check the commit changes using the provided command along with the “-p” flag:

git whatchanged -p

 

As you can see, there are two commits in the above-provided output with the applied changes before and after file modification.

Example 3: Display Previous Commits Information

Likewise, to display the commits changes a few hours or a few days back, the user can use the “–since” flag with the time as shown:

git whatchanged --since="2 days ago"

 

The commits applied in the past two days have been displayed.

What is the Difference Between git-log and git-whatchanged?

In Git Bash, the “git whatchanged” and “git log” commands are used to display similar information. The only difference is that the “git whatchanged” command is the ancient command used in older versions of Git, but has been replaced with “git log”. Apart from that, the “git log” file displays the merged file content while the “git whatchanged” command displays the files that were part of the commit. For the demonstration, see the below-provided image:

git log

 

Conclusion

The “git whatchanged” command shows the past commits applied in the file. To use this command, use the syntax “git whatchanged <option>”. Without the option, it displays all commits while the “-p” option displays the difference between the previous and new commits. A detailed guide on using the “git whatchanged” command has been covered in this blog.

About the author

Abdul Mateen

I hold a bachelor's degree in Computer Science and have a good technical background. As an author, I break down technical concepts in a clear and concise manner. Learning new skills and exploring new technologies is my passion.