How to list all commits that changed a specific file?

Viewed 386631

Is there a way to list all commits that changed a specific file?

17 Answers

To get all commits for a specific file use:

git rev-list HEAD --oneline FileName

For example

git rev-list HEAD --oneline index.html

Output

7a2bb2f update_index_with_alias
6c03e56 update_changes
e867142 Revert "add_paragraph"

See gif imagegit commits for specific files

If you wish to see all changes made in commits that changed a particular file (rather than just the changes to the file itself), you can pass --full-diff:

git log -p --full-diff [branch] -- <path>

To just get a list of the commit hashes, use git rev-list:

 git rev-list HEAD <filename>

Output:

b7c4f0d7ebc3e4c61155c76b5ebc940e697600b1
e3920ac6c08a4502d1c27cea157750bd978b6443
ea62422870ea51ef21d1629420c6441927b0d3ea
4b1eb462b74c309053909ab83451e42a7239c0db
4df2b0b581e55f3d41381f035c0c2c9bd31ee98d

Which means five commits have touched this file. It's in reverse chronological order, so the first commit in the list b7c4f0d7 is the most recent one.

Related