Git Commit History

Glory Kim
Glory KimSoftware Engineer, Loom
Published: December 1, 2023

Viewing a single git commit’s history

The git show command is used to view the changes of a specific commit:

Bash
git show <commit-hash>

For example, I can type git show 0f8497 to see the log message and the changes that occurred in this specific commit. On the left, we have the command and the right pane is the result with the diff.

Show the last git commits

To see the changes made in the last commit without using a hash, you can use the git show HEAD command. The HEAD here refers to the most recent commit within the git history of the project.war. You can use HEAD~1 to go back an extra commit, HEAD~2 to go back two, etc.

Viewing a git branch’s entire history

Each branch has a commit history. To list commits as a view of a branch's history, you can use the git log command with the branch name.

  • git log: shows the commit history for the branch currently checked out. If you have not checked out a branch, this will show you the commit history of the entire repository.
  • git log <branch-name>: shows the commit history for the specified branch and any commits shared by it's parent branches
  • git log <file-path>: shows the commit history of the file path

As a developer working at a fast paced startup, I like to use git log -n --oneline to view a summary of the last n commits in one-liners.

The screenshot above compares just running git log vs git log -4 --oneline.

Using GitHub to show commit history

To view the commit history of a repository on Github, you can click on  the “Commits” button on the homepage of the project. This re-routes to a URL of the form

YAML
https://github.com/company-name/repository-name/commits/main

and shows a list of the commits made to the project with full detail. Below is a screenshot of the React library’s most recent commits.

Use git reflog to recover lost commits

There may be instances when you use git log but the commit you are searching for is not showing up. With Git, it's possible to lose a commit by accidentally using commands like git reset --hard or through Git's garbage collection which removes unreferenced objects from the repository. These commits may not show up when calling git log, but you may be able to recover it using git reflog.

Unlike git log, git reflog is a local recording of changes made and tracks commits across every branch. By default, this tool keeps the record for 90 days and lets you return to old commits not referenced by any branches.

Use AI to recall these various git commit history commands

If you’re using Warp as your terminal, you can use Warp’s AI Command Search feature to surface the various commands to check history discussed above.

The easiest way to do this is to trigger the feature with #, and type what you are looking for, such as:

Bash
$ # show lost commits

Written by
Glory Kim
Glory KimSoftware Engineer, Loom
Filed under

Related articles


Git Clone, Push, And Pull Over SSH

Learn how to set up an SSH key to clone, push, and pull a Git repository over the SSH protocol.

Undo a Git Rebase

This post will show you how to undo a rebase using git reset, git rebase and git revert

Prompt Show Git Branch In Prompt

Enhance your terminal with a custom Git prompt. Learn different ways to integrate this contextual info, from custom shell functions to Warp context chips and toolkits like Starship and P10K.

Create Folder In GitHub Repository

Learn how to create and push one or more empty directories in a Git repository using `.placeholder` and `README.md` files using both the CLI and the GitHub interface.

Adding a Submodule in Git

This post will show you how to simply add a submodule to a local repository, clone a repository with a submodule, and work within a repository that has a submodule.

Git Push Origin

A breakdown of git push origin

Undo a git push

This post will show you had to simply undo a git push three different ways.

Undo Git Add

Learn how to effectively use 'git add' to stage files in Git for committing, and discover two powerful methods to undo accidental stagings.

How To Remove Secrets From The Git History Remove Secrets From The Git History

Learn how to remove secrets from the Git history using the BFG and git-filter-repo command-line tools.

Change Git Origin Remote URL

Learn how to change the remote url of a local git-enabled directory using the git-remote command and Warp's workflow feature.

Amend a Git Commit

Making changes to a previous commit

How To Create a Git Repository

Creating repos in various scenarios with git