by Sai gowtham

How to view the commit history in Git

How to view the commit history in Git

In this tutorial, we are going to learn about how to view the commit history in git with the help of examples.

Viewing commit history

To view the commit history we need to use the git log command followed by the -p flag.

-p means patch where it shows the difference occur in each commit.

Example:

git log -p

when you run the above command, It will display the commit history in reverse chronological order(last to first) similar to the below output

commit a6537cdc1d033d3853829e6baa194df44b750422 (HEAD -> master)
Author: saigowthamr <saigowthamr@gmail.com>
Date:   Wed Feb 25 05:09:03 2020 +0530

    changed data

diff --git a/n.js b/n.js
index 05c9bb3..710f139 100644
--- a/n.js
+++ b/n.js
@@ -6,3 +6,8 @@ dgf
 New line
+
+decodeURI
+
+
+hello
\ No newline at end of file

commit fb2h5925202199ff6dc62763303c9aa33ff8d3d9
Author: saigowthamr <saigowthamr@gmail.com>
:

If you want to view the number of insertions and deletions in each commit use --stat option.

git log --stat

Output:

commit a6537c241d033d3853829e6baa294df14b750422 (HEAD -> master)
Author: saigowthamr <saigowthamr@gmail.com>
Date:   Wed Feb 25 05:09:03 2020 +0530

    fixed typos

 n.js | 5 +++++
 1 file changed, 5 insertions(+)

commit fb265925t402999ff6zc62763343c9aa33ff8d3d9
Author: saigowthamr <saigowthamr@gmail.com>
Date:   Tue Feb 25 05:04:05 2020 +0530

    added some text

 n.js | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

commit df92196v4d6f4680b191204b70c7db96cfa60d47
Author: saigowthamr <saigowthamr@gmail.com>
Date:   Tue Feb 18 05:01:40 2020 +0530

    added numbers

Viewing commit history of an individual file

To view the commit history of an individual file we need to use the git log command followed by the -p flag and ‘name of the file’.

git log -p yourfilename

Viewing the list of modified files

The --name-only flag helps to view the list of modified files in each commit.

Example:

git log --name-only

Output:

commit a6537c1c1dnj3d3853829e6baa294df14b750422 (HEAD -> master)
Author: saigowthamr <saigowthamr@gmail.com>
Date:   Wed Feb 25 05:09:03 2020 +0530

    errors fixed

app.js

commit fb26592520299cdff6dc62763343c9aa33ff8d3d9
Author: saigowthamr <saigowthamr@gmail.com>
Date:   Tue Feb 25 05:04:05 2020 +0530

   added head tags

app.js
index.html

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
26,545 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
221,520 students enrolled
44 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
114,575 students enrolled
21 hours of video content
View Course