Viewing the commit history
Viewing a list of the latest commits
If you want to see what's happened recently in your project, you can use git log. This command will output a list of the latest commits in chronological order, with the latest commit first.
Every commit in the list will look a little something like this:
commit d240853866f20fc3e536cb3bca86c86c54b723ce
Author: Robert Lyall <rob@atech.media>
Date: Fri Apr 26 11:37:39 2019 +0100
Initial commit
You'll be able to see the name of who made the commit, their e-mail address, what time the commit was made, and the message they entered when they committed.
Commit hashes
The long string following the word commit is called the commit hash. It's unique identifier generated by Git. Every commit has one, and I'll show you what they're used for shortly.
Note: The "commit hash" is sometimes called a Git commit "reference" or "SHA".
Navigating and exiting the list of commits
You can either use the arrow keys to navigate up and down, or press the spacebar to view the next page. To exit the list, just press the letter q on your keyboard.
A bit more information
Just knowing that some changes took place is great, but often you want to know exactly what changed in each file. Don't worry, Git has got you covered!
By running git log -p, you'll get the same list as before, however each commit will have a list of the files that have been added/modified/removed, as well as the actual changes themselves.
Each commit in the list will look a little something like this:
commit 8fd3350cf6fba8bcd4abc7233d4ff6b81dd6ed3c
Author: Robert Lyall <rob@atech.media>
Date: Fri Apr 26 14:02:54 2019 +0100
Add the correct link to Brie
diff --git a/index.html b/index.html
index f501e7f..c23c354 100644
--- a/index.html
+++ b/index.html
@@ -48,7 +48,7 @@
<li class="product">
<img alt="Brie" class="product__image" src="/assets/images/cheese/brie.svg" />
<h3 class="product__name">
- <a class="product__link" href="#">Brie</a>
+ <a class="product__link" href="/cheese/brie">Brie</a>
</h3>
</li>
<li class="product">
Note: If you're wondering what "diff" means, it's short for difference, and it's essentially a summary of file changes between two commits in your repository.
Looking up changes for a specific commit
If you have the hash for a commit, you can use the git show command to display the changes for that single commit.
git show 5eba8ab3b718a6ab6610186be934ba214e228a58
The output is identical to each individual commit when using git log -p.
commit 5eba8ab3b718a6ab6610186be934ba214e228a58 (HEAD -> master)
Author: Robert Lyall <rob@atech.media>
Date: Fri Apr 26 14:03:11 2019 +0100
Remove Cheddar
diff --git a/index.html b/index.html
index c23c354..ec42f1d 100644
--- a/index.html
+++ b/index.html
@@ -51,12 +51,6 @@
<a class="product__link" href="/cheese/brie">Brie</a>
</h3>
</li>
- <li class="product">
- <img alt="Cheddar" class="product__image" src="/assets/images/cheese/cheddar.svg" />
- <h3 class="product__name">
- <a class="product__link" href="#">Cheddar</a>
- </h3>
- </li>
<li class="product">
<img alt="Robiola" class="product__image" src="/assets/images/cheese/robiola.svg" />
<h3 class="product__name">
Commit hashes are generally unique enough for you to use the first few letters/numbers when looking up a hash rather than the full hash.
So, you can just use git show 5eba8a instead to get the same result.
git log is quite powerful and you can provide lots of options. Keep reading for some of the most useful ones.
Filtering and formatting the log
When your project has hundreds or thousands of commits, the full git log output can be overwhelming. Git provides several flags to narrow down exactly what you need.
Compact output with --oneline
The --oneline flag condenses each commit to a single line showing the abbreviated hash and commit message:
git log --oneline
5eba8ab Remove Cheddar
8fd3350 Add the correct link to Brie
d240853 Initial commit
This is handy when you just need a quick overview of recent activity.
Visualizing branches with --graph
If your project uses branches, the --graph flag draws an ASCII representation of the branch structure alongside the log:
git log --oneline --graph --all
* 5eba8ab (HEAD -> main) Remove Cheddar
| * a3f1c72 (feature/add-gouda) Add Gouda to the list
|/
* 8fd3350 Add the correct link to Brie
* d240853 Initial commit
Limiting the number of commits
To see only the last few commits, pass a number with the -n flag (or just use the number directly):
git log -5
This shows the last 5 commits. You can combine it with other flags, e.g. git log --oneline -10 for a quick summary of the last 10 commits.
Filtering by author
To see commits from a specific person:
git log --author="Robert"
Git matches the value against the author name and email, so partial matches work too.
Filtering by date
To see commits within a date range, use --since and --until:
git log --since="2024-01-01" --until="2024-06-30"
Relative dates also work: --since="2 weeks ago" or --since="yesterday".
Viewing changes for a specific file
If you only care about the history of one file, pass the file path after a -- separator:
git log -- path/to/file.html
This lists every commit that modified that file. Combine it with -p to see the actual diff for each change:
git log -p -- path/to/file.html
This is particularly useful for tracking down when and why a specific line was changed. You can also pair it with --oneline for a quick overview:
git log --oneline -- src/index.html
Understanding branch and HEAD annotations
When you run git log, you may notice annotations next to some commit hashes like (HEAD -> main, origin/main, feature-branch). These tell you where your branches and remote tracking branches currently point:
HEAD -> mainmeans your local working copy is at this commit and on themainbranchorigin/mainmeans the remotemainbranch is also at this commitfeature-branchmeans your localfeature-branchis at this same commit
This is useful for quickly seeing whether your local branch is ahead of, behind, or in sync with the remote. For example, if HEAD -> main appears on a newer commit than origin/main, you have local commits that haven't been pushed yet.
Next steps
Now that you can navigate your commit history, you might want to explore related commands:
- git diff — compare changes between commits, branches, or your working directory
- Committing file changes — how to create new commits
- git checkout — switch branches or restore files from a previous commit
- git blame — find out who last modified a specific line in a file
Once your team is committing regularly, DeployHQ can watch your repository and automatically deploy every push to your servers — so your commit history translates directly into production releases.