Advertisement
Advertisement


How can I list all commits that changed a specific file?


Question

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

2020/05/03
1
821
5/3/2020 8:46:34 PM

Accepted Answer

The --follow works for a particular file

git log --follow -- filename

Difference to other solutions given

Note that other solutions include git log path (without the --follow). That approach is handy if you want to track e.g. changes in a directory, but stumbles when files were renamed (thus use --follow filename).

2019/12/20
1108
12/20/2019 2:33:26 PM

git log path should do what you want. From the git log man:

[--] <path>…

Show only commits that affect any of the specified paths. To prevent confusion with 
options and branch names, paths may need to be prefixed with "-- " to separate them
from options or refnames.
2010/09/13

I have been looking at this closely and all these answers don‘t seem to really show me all the commits across all the branches.

Here is what I have come up with by messing around with the gitk edit view options. This shows me all the commits for a file regardless of branch, local, reflog, and remote.

gitk --all --first-parent --remotes --reflog --author-date-order -- filename

It also works with git log:

git log --all --first-parent --remotes --reflog --author-date-order -- filename
2019/11/04

Use the command below to get commits for a specific file:

git log -p filename
2016/11/16

It should be as simple as git log <somepath>; check the manpage (git-log(1)).

Personally I like to use git log --stat <path> so I can see the impact of each commit on the file.

2018/10/25

Alternatively (since Git 1.8.4), it is also possible to just get all the commits which has changed a specific part of a file. You can get this by passing the starting line and the ending line number.

The result returned would be the list of commits that modified this particular part. The command goes like:

git log --pretty=short -u -L <upperLimit>,<lowerLimit>:<path_to_filename>

where upperLimit is the start_line_number and lowerLimit is the ending_line_number

More Info - https://www.techpurohit.com/list-some-useful-git-commands

2019/04/20

Source: https://stackoverflow.com/questions/3701404
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]