| by Arround The Web | No comments

How Can I Show What a Commit Did?

In Git, a commit represents a snapshot of the entire Git repository at a certain point in time. When users make changes to files in the repository, they stage those changes and then create a commit to save those changes. More specifically, when a commit is created, Git creates a snapshot of the current state of the repository including all the changes that were staged. Each commit contains information including the commit message, date, author, and files that were added, modified, or deleted. Users can view all changes made in the commits.

This write-up will demonstrate the methods to show what a particular commit did.

How to Show What a Commit Did?

Different Git commands can be used to show what a particular commit did, such as:

Method 1: View Commit Changes Using “git show <commit-id>” Command

The “git show” command along with the commit ID shows detailed information about that commit including the commit message, author name, date, and time. It also shows what a particular commit did.

Step 1: Select Desired Commit

First, display the commit history, and choose a particular commit.

git log --oneline

The below output shows all the commit history. We have selected the “3245529” commit id:

Step 2: View Commit Changes

Then, utilize the “git show” command along with the selected commit ID to view its changes:

git show 3245529

The below output shows the changes made to the selected commit. In the highlighted part, the green text along with the “+” symbol represents the new lines added to the file in the commit:

Moreover, the “–stat” option can also be used in the same command to view the brief list of changes:

git show 3245529 --stat

The below screenshot indicates that three insertions have been added to this commit:

Method 2: View Commit Changes Using “git diff <commit-id>^!” Command

The “git diff” command with the specific commit ID is used to view the changes made to that commit. Use the provided command and add the “^!” symbols to exclude all of the parent commits from the diff:

git diff 3245529^!

In the below screenshot, the highlighted part shows the changes added in the selected commit:

We have explained the easiest methods to show what a specific commit did.

Conclusion

To show what a particular commit did, first, select the desired commit and copy its commit ID. Then, execute the “git show <commit-id>” or “git diff <commit-id>^!” command to view the changes added to that commit. This write-up demonstrated the methods to show what a particular commit did in Git.

Share Button

Source: linuxhint.com

Leave a Reply