search
Search
Login
Unlock 100+ guides
menu
menu
web
search toc
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
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

Viewing commit history in Git

schedule Aug 11, 2023
Last updated
local_offer
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

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
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!