Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

search - How do I find the most recent git commit that modified a file?

I want to find the most recent commit that modified a source file.

I can use git blame to see all the dates for commits by each line, but it’s difficult to see exactly which commit was the last one to touch the file.

How can I find the last commit that touched a given file in my git repository?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

git log supports looking at the history of specific files (and directories), so you can call it like this:

git log my/file.c

If you really only want to list the one most recent commit, for example to use it in a script, use the -n 1 option:

git log -n 1 --pretty=format:%H -- my/file.c

--pretty=format:%h tells git log to show only the commit hash. The -- separater stops the file name from getting interpreted as a commit name, just in case it's ambiguous.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...