0

I want get latest commit id or changes that was made in particular line of file.

I'm working with big team and there are daily changes commit in repo, now I want to find what as the last changes made in any file file/xyz.py line number 20 or in range of 20 to 30. So it is difficult for me to check every commit if the file was edited or not.

Is there any command that can show me last changes or commit id by finding when was last time the file was touched or edited in that line or range of line?

Avi
  • 1,424
  • 1
  • 11
  • 32

3 Answers3

2

You can pass a path into git log.

git log --all -n1 -- PATH/TO/FILE

Add --follow to detect name changes

git log --all -n1 --follow -- PATH/TO/FILE

Add --L <n,m> with min and max line numbers

git log --all --follow -n1 -L<nm,m> -- PATH/To/FILE

You can also use git blame to specify line numbers. Use n and m to specify line number range.

git blame -L <n,m> <HEAD or BRANCH> -- PATH/TO/FILE
EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
0

Git blame with the option "-L" is what you are looking for. git blame -L20,30 -- file/xyz.py in your case.

See https://www.git-scm.com/docs/git-blame for more details

Abel
  • 688
  • 6
  • 19
0

The high-level function of git blame is the display of author metadata attached to specific committed lines in a file. This is used to examine specific points of a file's history and get context as to who the last author was that modified the line.

git blame -L 20,30 -- <file_path>

The -L option will restrict the output to the requested line range. Here we have restricted the output to lines 20 through 30.

For more information: https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-blame

LuVu
  • 1,053
  • 1
  • 7
  • 23