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?
- Example 1: Display All Commits
- Example 2: Display the Difference Between Previous and New Commits
- Example 3: Display Previous Commits Information
- What is the Difference Between “git-whatchanged” and “git-log”?
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:
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:
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:
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:
After that, check the file’s status using the command stated below:
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:
The file has been tracked successfully.
Now, commit changes to the repository and use the “-m” flag for adding the commit message:
Let’s check the commit changes using the provided command along with the “-p” flag:
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:
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:
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.