我如何找到修改文件的最新git提交? [英] How do I find the most recent git commit that modified a file?

查看:108
本文介绍了我如何找到修改文件的最新git提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到修改源文件的最新提交。

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

我可以使用 git blame 来查看每行提交的所有日期,但很难准确地看到哪个提交是最后一个触及该文件的文件。

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.

如何在git存储库中找到触及给定文件的最后一个提交?

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

推荐答案

git log 支持查看特定文件(和目录)的历史记录,因此您可以编写它:

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

git log my/file.c

如果您真的只想列出例如在脚本中使用它,您可以使用 -n 1

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

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

- pretty = format:%h 告诉 git log 只显示提交哈希(感谢TheBamf)。 - separater停止将文件名解释为提交名称,以防万一不明确。

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

这篇关于我如何找到修改文件的最新git提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆