Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

Git Tutorial

Git HOME Git Intro Git Install Git Config Git Get Started Git New Files Git Staging Git Commit Git Remove and Move Git Tagging Git Stash Git History Git Diff Git Blame Git Help Git Branch Git Merge Git Workflow Git Best Practices

Git and GitHub

GitHub Get Started Git What is SSH? GitHub Add SSH GitHub Set Remote GitHub Edit Code Pull from GitHub Push to GitHub GitHub Branch Pull Branch from GitHub Push Branch to GitHub GitHub Flow GitHub Pages Git GUI Clients

Git Contribute

GitHub Fork Git Clone from GitHub GitHub Send Pull Request

Git Undo

Git Revert Git Reset Git Clean Git Amend Git Rebase Git Reflog Git Recovery

Git Advanced

Git .gitignore Git .gitattributes Git Large File Storage (LFS) Git Signing Commits/Tags Git Cherrypick & Patch Git Bisect Git Merge Conflicts Git CI/CD Git Hooks Git Submodules Git Worktree Git Remote Advanced

Git and Bitbucket

Bitbucket Get Started Bitbucket Add SSH Bitbucket Set Remote Bitbucket Edit Code Bitbucket Branch Bitbucket Pages Bitbucket Fork Git Clone from Bitbucket Bitbucket Send Pull Request

Git and GitLab

GitLab Get Started GitLab Add SSH GitLab Set Remote GitLab Edit Code GitLab Branch GitLab Pages GitLab Fork Git Clone from GitLab GitLab Send Pull Request

Git Cert

Git Certificate

Git Reference

Git Glossary

Git Exercises

Git Terminal Git Exercises Git Challenges Git Quiz Git Syllabus Git Study Plan

Git History


Share

What is Git History? Why Use It?

Git keeps a detailed record of every change made to your project.

You can use history commands to see what changed, when, and who made the change.

This is useful for tracking progress, finding bugs, and understanding your project's evolution.


Key Commands for Viewing History

  • git log - Show full commit history
  • git log --oneline - Show a summary of commits
  • git show <commit> - Show details of a specific commit
  • git diff - See unstaged changes
  • git diff --staged - See staged changes

Best Practices for Viewing History

  • Make frequent, meaningful commits to keep your history clear.
  • Write clear commit messages so you and your team can understand changes later.
  • Use git log --oneline for a quick overview of your commit history.
  • Use git diff before committing to review your work.

See Commit History (git log)

Show a detailed list of all commits in your repository:

Example: Full Commit History

git log
commit 9a8cf23957db088dcaf52940261e1537c25e1c2f (HEAD -&gt; main)
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Updated index.html with a new line

commit ee6f3208cea23ba9776153abf6bd729b0da72e8d
Merge: 1a9b314 4e030be
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Merge branch 'feature-x'

commit 1a9b31454110f6165135d0c2f066fd763734d98e
Author: Alice &lt;alice@example.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Add about page

commit 4e030be15317040b69ab31f826a47c7ad732af2d (feature-x)
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Add contact form

commit 09f62be0f26527123f7c10ec948706d32a10c0cf
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Initial commit
Try it Yourself »

This command shows all commits, including author, date, and message.

Use the arrow keys to scroll, and press q to quit.

Tip: While viewing the log, you can search for a word by typing / followed by your search term
(for example, /fix), then press n to jump to the next match.

Press q at any time to quit.


Show Commit Details (git show <commit>)

See all the details and changes for a specific commit:

Example: Show Commit Details

git show 9a8cf23
commit 9a8cf23957db088dcaf52940261e1537c25e1c2f (HEAD -&gt; main)
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Updated index.html with a new line

diff --git a/index.html b/index.html
index 597ecf5..c57442b 100644
--- a/index.html
+++ b/index.html
@@ -1 +1,2 @@
 &lt;h1&gt;Hello world!&lt;/h1&gt;
+&lt;p&gt;A new line in our file!&lt;/p&gt;
Try it Yourself »

This command shows everything about a commit: who made it, when, the message, and the exact changes.



Compare Changes (git diff)

See what is different between your working directory and the last commit (unstaged changes):

Example: See Unstaged Changes

git diff
diff --git a/index.html b/index.html
index c57442b..ae5f439 100644
--- a/index.html
+++ b/index.html
@@ -1,2 +1,2 @@
-&lt;h1&gt;Hello world!&lt;/h1&gt;
+&lt;h1&gt;Hello Git!&lt;/h1&gt;
 &lt;p&gt;A new line in our file!&lt;/p&gt;
Try it Yourself »

This command shows changes you have made but not yet staged for commit.


Compare Staged Changes (git diff --staged)

See what is different between your staged files and the last commit:

Example: See Staged Changes

git diff --staged
diff --git a/index.html b/index.html
index c57442b..ae5f439 100644
--- a/index.html
+++ b/index.html
@@ -1,2 +1,2 @@
-&lt;h1&gt;Hello world!&lt;/h1&gt;
+&lt;h1&gt;Hello Git!&lt;/h1&gt;
 &lt;p&gt;A new line in our file!&lt;/p&gt;
Try it Yourself »

This command shows changes that are staged and ready to be committed.


Compare Two Commits (git diff <commit1> <commit2>)

See what changed between any two commits:

Example: Compare Two Commits

git diff ee6f320 9a8cf23
diff --git a/index.html b/index.html
index 597ecf5..c57442b 100644
--- a/index.html
+++ b/index.html
@@ -1 +1,2 @@
 &lt;h1&gt;Hello world!&lt;/h1&gt;
+&lt;p&gt;A new line in our file!&lt;/p&gt;
Try it Yourself »

This command shows the differences between two specific commits.


Show a Summary of Commits (git log --oneline)

Show a short summary of each commit (great for a quick overview):

Example: Oneline Log

git log --oneline
9a8cf23 (HEAD -&gt; main) Updated index.html with a new line
ee6f320 Merge branch 'feature-x'
1a9b314 Add about page
4e030be (feature-x) Add contact form
09f62be Initial commit
Try it Yourself »

This command shows each commit on a single line for easy reading.


Show Commits by Author (git log --author="Alice")

See only the commits made by a specific author:

Example: Commits by Author

git log --author="Alice"
commit 1a9b31454110f6165135d0c2f066fd763734d98e
Author: Alice &lt;alice@example.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Add about page
Try it Yourself »

This command filters the log to show only commits by the author you specify.


Show Recent Commits (git log --since="2 weeks ago")

See only commits made in the last two weeks:

Example: Recent Commits

git log --since="2 weeks ago"
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803
Author: w3schools-test &lt;test@w3schools.com&gt;
Date:   Fri Mar 26 09:35:54 2021 +0100

    Updated index.html with a new line
Try it Yourself »

This command shows only the commits made in a recent time frame.


Show Files Changed Per Commit (git log --stat)

See which files were changed in each commit and how many lines were added or removed:

Example: Log with Stats

git log --stat
commit 9a8cf23957db088dcaf52940261e1537c25e1c2f (HEAD -&gt; main)
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Updated index.html with a new line

 index.html | 1 +
 1 file changed, 1 insertion(+)

commit ee6f3208cea23ba9776153abf6bd729b0da72e8d
Merge: 1a9b314 4e030be
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Merge branch 'feature-x'

commit 1a9b31454110f6165135d0c2f066fd763734d98e
Author: Alice &lt;alice@example.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Add about page

 about.html | 1 +
 1 file changed, 1 insertion(+)

commit 4e030be15317040b69ab31f826a47c7ad732af2d (feature-x)
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Add contact form

 contact.html | 1 +
 1 file changed, 1 insertion(+)

commit 09f62be0f26527123f7c10ec948706d32a10c0cf
Author: W3Schools &lt;test@w3schools.com&gt;
Date:   Wed Jan 15 10:00:00 2025 +0000

    Initial commit

 index.html | 1 +
 1 file changed, 1 insertion(+)
Try it Yourself »

This command adds a summary of file changes to each commit in the log.


Show a Branch Graph (git log --graph)

See a simple ASCII graph of your branch history (great for visualizing merges):

Example: Log with Graph

git log --graph --oneline
* 9a8cf23 (HEAD -&gt; main) Updated index.html with a new line
*   ee6f320 Merge branch 'feature-x'
|\  
| * 4e030be (feature-x) Add contact form
* | 1a9b314 Add about page
|/  
* 09f62be Initial commit
Try it Yourself »

This command shows a simple graph of your branch and merge history.


Troubleshooting

  • Can't see your changes? Make sure you have committed your work. Uncommitted changes won't appear in the history.
  • Log is too long? Use git log --oneline or git log --since to make it easier to read.
  • How do I quit the log view? Press q to exit the log or diff view.

Note: Exploring your history helps you understand what changed, when, and why.




Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.