Viewing a single git commit’s history
The git show command is used to view the changes of a specific commit:
git show <commit-hash>
Run in Warp
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 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:
$ # show lost commits
Run in Warp
Written by
Glory Kim
Software Engineer, Loom
Filed Under
Related Articles
Undo A Git Pull
How to effectively remove the commits introduced by a pull in Git using git-reset and preserve your local changes using git-stash. Also, how to cancel an unmerged pull request on GitHub.
Undo a Git Merge
How to rollback the changes introduced by a merge in Git by adding new opposite commits using git-revert and effectively removing commits using git-reset.
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.
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.
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.
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.
Undo a Git Rebase
This post will show you how to undo a rebase using git reset, git rebase and git revert
Git Push Origin
A breakdown of git push origin
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.
Git Push Tags
This post will show you how to push a single tag, multiple tags, all tags, and tags with commits.
Undoing Git Commits
Explore ways to undo a commit, including git reset, git checkout, and git revert with git while preserving commit history.