Table of Contents
In this article, we will see 3 Best ways to list all the changed files after git commit. If you are a developer or a programmer working on a project and regularly committing your codes to a Git Repository then you might have faced a situation where you need to check all the files that are changed or modified after Git Commit. Very often, developers look for changes done during various commits before pushing their code to Git Repository.
While there are multiple ways to review the modified files after git commit depending on the Repository platform you are using, we will primarily keep our focus on methods using git tool. We will see how git command can be used effectively to understand the list of files changed or modified after every git commit.
What is Git Commit ID
It is a unique SHA-1 hash which gets created after every commit done by the Git User. It basically contains information about all the changes done in that specific commit.
Best Ways to List all the Changed Files After Git Commit
Also Read: 10 Awesome tee command examples in Linux for Beginners
Method 1: Using git log
One of the very popular method to check all the Commit IDs and the changes done through this commit ID is by using git log
command. If you simply run git log command then you will get list of all Commits done till now. But if you use git log -p
command, then you will see all the Commits along with the changes done in each Commit. So output will be pretty long in this method. More on git log Man Page.
cyberithub@cloudshell:~ $ git log -p commit 76d585cd4cd61af254775562249050460b287861 (HEAD -> feature, master, dev) Date: Mon Mar 29 08:22:47 2021 +0000 Next Commit diff --git a/.bash_history b/.bash_history new file mode 100644 index 0000000..cf09271 --- /dev/null +++ b/.bash_history @@ -0,0 +1,4 @@ +pwd +git branch +git init +git branch diff --git a/.bash_logout b/.bash_logout new file mode 100644 index 0000000..de4f5f7 --- /dev/null +++ b/.bash_logout
NOTE:
gcloud
shell. You might be using some Linux based machine to commit your code. You can use any platform with git utility installed. It really doesn't matter.
Method 2: Using git show
Another very useful command that you can use is git show
command. Using this method, you can check all the changes done on a Specific Commit ID. Syntax to use the command is git show <Commit ID>
. You can get all the Commit ID from git log
command. Here we are checking the list of changes for da475798411a3e2769219b4a7655b6821c4d1901
commit ID using git show
command as shown below.
cyberithub@cloudshell:~$ git show da475798411a3e2769219b4a7655b6821c4d1901 commit da475798411a3e2769219b4a7655b6821c4d1901 (HEAD -> feature, origin/feature) Date: Mon May 10 09:10:18 2021 +0000 Feature Commit diff --git a/newfile b/newfile index 68053be..2327a60 100644 --- a/newfile +++ b/newfile @@ -1,77 +1,118 @@ +diff --git a/cloudbuild.yaml b/cloudbuild.yaml +index 07ff190..bde9212 100644 +--- a/cloudbuild.yaml ++++ b/cloudbuild.yaml +@@ -16,7 +16,7 @@ steps: + #git diff HEAD^^^^ | git apply + #git remote add origin https://source.developers.google.com/p/${_PROJECT}/r/${_REPO_NAME} + #git config core.sparseCheckout true +- git checkout -f $(git log | head -1 | awk '{ print $2 };') ++ git checkout $(git log | head -1 | awk '{ print $2 };') newfile + #git rev-list ^HEAD~1HEAD + #echo "sql/demo.sql" >> .git/info/sparse-checkout + #git pull --depth=1 origin feature diff --git a/newfile b/newfile -index 5229bdf..e69de29 100644 +index 68053be..e69de29 100644 --- a/newfile +++ b/newfile
Method 3: Using git diff
One more important command that you can use is git diff command to check the list of files modified between two Commit IDs. Syntax of this command is git diff --name-only <Start Commit ID>..<End Commit ID>
. Here you need to provide start Commit ID and end Commit ID to know all the changes done between those two commit IDs. For example, we have randomly chosen start commit ID as 30b1d202d7e2727085d7dc8349ce8b0f67686f2d
and end commit ID as da475798411a3e2769219b4a7655b6821c4d1901
from git log
command as shown below. From the output you can see that between these two commits, cloudbuild.yaml
and newfile
are modified.
cyberithub@cloudshell:~$ git diff --name-only 30b1d202d7e2727085d7dc8349ce8b0f67686f2d..da475798411a3e2769219b4a7655b6821c4d1901 cloudbuild.yaml newfile