Git: Find last edits from a specific user in a specific file
Asked Answered
P

3

5

I have a project which sources are controlled with help of git.

Right now I want to find out when my teammate made last edits in a specific file. I want to find out SHA1 of commit or to see his edits as diff.

I guess I can use git log --stat <path/to/file> and review list of all commits where my file was changed.

Are there any quick ways to do it?

Poulter answered 5/8, 2011 at 12:36 Comment(0)
S
9

you can use git log with a pathspec and --author option:

git log --author=your_teammate -- path/to/file
Sponsor answered 5/8, 2011 at 12:44 Comment(1)
Wow. I've forgot to review git help log. Thank you. git log --author=your_teammate -- path/to/file -n 1 does the work :)Poulter
B
3

Yes! you can use git blame

git blame <file>

every line of that file will be shown who is the one edited the last.

Brehm answered 5/8, 2011 at 12:40 Comment(3)
If you have a file is thousands of lines long, this is a horribly tedious way to figure out what the author wantsWilford
Actually git blame will not help me if edits of my teammate where overwritten in later commits by another author.Poulter
@Konstantin: it seems that your question is not asking what you describe in OP :pBrehm
W
2

I would use this line
git log --format="%H--%ad-%an" fileName

If you only want the last change, use this
git log --format="%H--%ad-%an" -n 1 fileName

If you are looking for a single specific author, pipe it through grep
git log --format="%H--%ad-%an" fileName | grep "Author Name"

Wilford answered 5/8, 2011 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.