search
Search
Publish
menu
menu search toc more_vert
Robocat
Guest 0reps
Thanks for the thanks!
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
help Ask a question
Share on Twitter
search
keyboard_voice
close
Searching Tips
Search for a recipe: "Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
icon_star
Doc Search
icon_star
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Navigate to
A
A
share
thumb_up_alt
bookmark
arrow_backShare
Twitter
Facebook

Viewing commit history in Git

Software Development
chevron_right
Git
chevron_right
Cookbooks
schedule Mar 9, 2022
Last updated
local_offer
Tags

To view commit history in Git we can use the git log command which prints out all commits which have been done until now, showing the most recent entries first.

Examples

Repository commit history

To view the commit history for the repository you are currently in:

git log
commit a4708a6a7d593e6119247baf4b126ca68dcf6417
Author: Harry Potter <example@email.com>
Date: Thur Oct 7 22:55:13 2021 -0700
Update version number
commit ab5adad5f531b039f3771ed7eae8e6de1b073995
Author: Harry Potter <example@email.com>
Date: Mon Oct 4 17:45:31 2021 -0700
Making initial changes
commit f24tqh25b3e450402ge8563abf99ad00de2209e6
Author: Harry Potter <example@email.com>
Date: Sat Oct 2 11:12:18 2021 -0700
Initial commit

Notice the log shows:

  • unique ID for each commit (called a hash)

  • the author of each commit

  • the date of the commit

  • the commit message

Specific file / directory commit history

To only view the commit history for a particular file or directory:

git log <path>

where <path> represents the filepath for the particular files or directories you would like to view the commit history for.

For example, to just view the commit history for a file called example.txt:

git log /Users/Harry/Desktop/project/example.txt
commit ab5adad5f531b039f3771ed7eae8e6de1b073995 (HEAD -> master)
Author: Harry Potter <example@email.com>
Date: Thu Oct 7 12:57:08 2021 +0900
second version

Display only latest x commits

To display only the latest x commits, we can pass - followed by the number of commits to restrict the output to. For example, to display only the latest 3 commits for example.txt we can run:

git log -3 /Users/Harry/Desktop/project/example.txt
robocat
Published by Arthur Yanagisawa
Edited by 0 others
Did you find this page useful?
thumb_up
thumb_down
Ask a question or leave a feedback...