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

后端 未结 6 1745
北荒
北荒 2020-11-28 20:23

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 difficu

6条回答
  •  有刺的猬
    2020-11-28 20:46

    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.

提交回复
热议问题