Git History

Divya Srinivasan

 What is Git History? Why Use It?

Git automatically keeps a complete record of every change made to your project over time.
By exploring this history, you can see what changed, when it changed, and who made those changes.
This is incredibly helpful for:
  • Tracking the progress of your work
  • Identifying and fixing bugs
  • Understanding how your project has evolved

Essential Commands for Viewing History

Here are some common Git commands to explore your project’s history:
  • git log – Display the full commit history with messages, authors, and dates
  • git log --oneline – Show a simplified view of the history with short commit hashes and messages
  • git show <commit> – View detailed information and changes for a specific commit
  • git diff – See the differences between your working directory and the last commit (unstaged changes)
  • git diff --staged – Show changes that have been staged and are ready to be committed

Best Practices for Working with Git History

  • Write clear, meaningful commit messages so history stays easy to understand.
  • Commit frequently to capture small, logical steps.
  • Use git log and related commands regularly to keep track of changes and spot issues early.
  • Avoid rewriting published history in shared branches unless absolutely necessary.

View Commit History (git log)

See a detailed list of all commits in your repository:

Example: 

Show Full Commit History
git log

Sample Output:

pgsql
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803 (HEAD -> master)
Author: w3schools-test
Date:   Fri Mar 26 09:35:54 2021 +0100

    Updated index.html with a new line
This command displays each commit’s ID, author, date, and commit message.
Use the arrow keys to scroll through the list, and press q to exit.

Show Commit Details (git show <commit>)

View all the information and changes for a specific commit.

Example:

 Show Commit Details
git show 09f4acd

Output:

text
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803 (HEAD -> master)
Author: w3schools-test
Date:   Fri Mar 26 09:35:54 2021 +0100

    Updated index.html with a new line

diff --git a/index.html b/index.html
index 1234567..89abcde 100644
--- a/index.html
+++ b/index.html
@@ ...
+New Title
This command displays everything about the commit:
  • Commit ID and branch
  • Author and date
  • Commit message
  • The actual file changes (diff)

 Compare Changes with git diff

See unstaged changes
Check what you’ve changed in your working directory since the last commit (but haven’t staged yet):
git diff

Example output:

diff
diff --git a/index.html b/index.html
index 1234567..89abcde 100644
--- a/index.html
+++ b/index.html
@@ ...
-Old Title
+New Title
This shows the difference between the last commit and your current working files.

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

Quickly see each commit summarized in a single line — perfect for an overview:

Example:

git log --oneline
09f4acd Updated index.html with a new line
8e7b2c1 Add about page
1a2b3c4 Initial commit
This command displays each commit’s abbreviated hash and message on one line, making the history easy to scan.

Show Commits by a Specific Author

View only the commits made by a particular author:
git log --author="Alice"

Example output:

sql
commit 1a2b3c4d5e6f7g8h9i0j
Author: Alice
Date:   Mon Mar 22 10:12:34 2021 +0100

    Add about page
This command displays the commit history filtered to include only commits made by the specified author.

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

View commits made within the last two weeks:
git log --since="2 weeks ago"

Example:

pgsql
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803
Author: w3schools-test
Date:   Fri Mar 26 09:35:54 2021 +0100

    Updated index.html with a new line
This command filters your commit history to display only the commits created in the past two weeks.

Show Files Changed Per Commit

Use the following command to see which files were modified in each commit, along with how many lines were added or removed:
git log --stat

Example output:

pgsql
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803
Author: w3schools-test
Date:   Fri Mar 26 09:35:54 2021 +0100

    Updated index.html with a new line

 index.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
This shows a summary of the files affected and the number of lines added or removed in each commit.

Visualize Branch History with a Graph

See a neat ASCII graph that shows your commits and where branches and merges happened:
git log --graph --oneline

Example output:

pgsql
* 09f4acd Updated index.html with a new line
* 8e7b2c1 Add about page
|\  
| * aabbccd Merge branch 'feature-x'
|/
This command gives you a quick, visual way to understand your project's branching and merging history.

Troubleshooting Tips

Changes not showing up?
Make sure you've committed them — only committed changes appear in the history.
Log too overwhelming?
Use git log --oneline for a shorter view, or filter by date with git log --since.
Stuck in the log or diff view?
Just press q to quit and return to the terminal.








Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send