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

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

问题描述

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

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 call it like 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, use the -n 1 option:

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

--pretty=format:%h 告诉 git log 只显示提交哈希.-- 分隔符阻止文件名被解释为提交名,以防万一它不明确.

--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.

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

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