Git helps the users while working on shared team projects repositories. All team members work together on the local Git repository, and after that commit and push all changes and newly created files to the remote repository. However, sometimes users want to see all commit changes that they have made before. Git permits its users to show all changes in commit with the help of commands.
In this study, we will provide the easiest way to show changes in Commit in Git.
How to Show Changes in Commit in Git?
To understand the procedure of showing changes in the commit, we will create a file, add, and commit it to the Git repository. Then, we will check the changes that we made in the repository.
Now, let’s head towards the procedure.
Step 1: Navigate to Git Directory
At first, navigate to the Git local directory with the help of the “cd” command:
Step 2: Check Status
Next, run the “git status” command to check the current status of Git directory:
Here, we have two untracked items in current Git directory “first demo/” and “test_file.txt”:
Step 3: Add File
Now, add the file in Git staging area using the “git add” command:
Below output indicates that we have successfully tracked the “test_file.txt” file in “update” Git directory:
Step 4: Check Status
Again, execute the “git status” command to verify the above action:
As you can see, our “test_file.txt” is added and modified:
Step 5: Commit Changes
Now, commit the changes in the Git for fast workflow using the below-provided command:
We have committed the changes with commit message to Git repo:
Step 6: Copy Commit Ref
Next, execute the “git log” command which will show all commit history of the current Git repo:
You will see the full commit history and copy the ref of any commit of which you want to show changes. Here, we have copied the ref of the below highlighted commit:
Step 7: Show Changes
Now, execute the “git diff” command with copied commit ref and add the “^!” special character at the end of ref:
As you can see, all changes which we have committed are displayed:
Note: Above execute commit ref will change against any commit and users. Kindly paste the ref of your commit of which you want to see the all changes.
That’s it! We have discussed the way to show changes in commits in Git.
Conclusion
To show the changes in commit in Git, first, open up the “Git Bast”, and navigate to the Git repository. Next, check the current status using “$ git status”, and add untracked files using the “git add” command. Again, check the status and commit the changes using the “$ git commit” command. Now, execute the “$ git log” command to see the history of all commit changes, and then copy the ref of any commit and execute it with the “$ git diff” command. This study illustrated the method of displaying changes in Commit in Git.