How do I see changes between commits

You can use git diff commitID1..commitID2 to see all the changes between two commits. You can see all the changes listed in the files and the code. The commitID1 is the starting commit, and commitID2 is the ending commit.

Let us see the same through a hands-on example on a real-world system and with an actual git codebase.

Using the “git log –oneline” command, you can see that the branch main has five commits listed.

~/repoone$ git log --oneline
4632c0d (HEAD -> main, origin/maincopy, origin/main, origin/HEAD) Adding empty directory
908d6ac Third commit in main
42296d0 Second commit in main
453424e This is first commit
2673111 Initial commit

To find the changes between two commits (the first and third), we issue git diff on their commit ids, as shown. You can see that it displays all the changes in files and the code.

~/repoone$ git diff 2673111..42296d0
diff --git a/dirone/fileone b/dirone/fileone
new file mode 100644
index 0000000..c2a1599
--- /dev/null
+++ b/dirone/fileone
@@ -0,0 +1 @@
+this is file one
diff --git a/filefour b/filefour
new file mode 100644
index 0000000..e69de29
diff --git a/filethree b/filethree
new file mode 100644
index 0000000..e69de29
diff --git a/filetwo b/filetwo
new file mode 100644
index 0000000..f8156fa
--- /dev/null
+++ b/filetwo
@@ -0,0 +1 @@
+this is file two

Click here to get details of a specific commit.

Check out this article to see changes after the last commit.