git 如何列出更改特定文件的所有提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3701404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:06:23  来源:igfitidea点击:

How can I list all commits that changed a specific file?

gitcommit

提问by Daniel

Is there a way to list all commits that changed a specific file?

有没有办法列出更改特定文件的所有提交?

回答by Hymanrabb1t

The --followworks for a particular file

--follow特定文件的作品

git log --follow -- filename

Difference to other solutions given

与给出的其他解决方案的区别

Note that other solutions include git log path(without the --follow). That approach is handy if you want to track e.g. changes in a directory, but stumbles when files were renamed(thus use --follow filename).

请注意,其他解决方案包括git log path(不包括--follow)。如果您想跟踪例如目录中的更改,这种方法很方便,但在重命名文件(因此使用--follow filename时会出错

回答by Gabe Moothart

git log pathshould do what you want. From the git logman:

git log path应该做你想做的。来自git log男人

[--] <path>…

Show only commits that affect any of the specified paths. To prevent confusion with 
options and branch names, paths may need to be prefixed with "-- " to separate them
from options or refnames.

回答by BigMiner

I have been looking at this closely and all these answers don‘t seem to really show me all the commits across all the branches.

我一直在仔细研究这个问题,所有这些答案似乎并没有真正向我展示所有分支的所有提交。

Here is what I have come up with by messing around with the gitk edit view options. This shows me all the commits for a fileregardless of branch, local, reflog, and remote.

这是我通过使用 gitk 编辑视图选项得出的结论。这向我显示了文件的所有提交,而不管分支、本地、引用日志和远程。

gitk --all --first-parent --remotes --reflog --author-date-order -- filename

It also works with git log:

它也适用于git log

git log --all --first-parent --remotes --reflog --author-date-order -- filename

回答by Sankar Subburaj

Use the command below to get commits for a specific file:

使用以下命令获取特定文件的提交:

git log -p filename

回答by rfunduk

It should be as simple as git log <somepath>; check the manpage (git-log(1)).

它应该很简单git log <somepath>;检查联机帮助页 ( git-log(1))。

Personally I like to use git log --stat <path>so I can see the impact of each commit on the file.

我个人喜欢使用,git log --stat <path>这样我就可以看到每次提交对文件的影响。

回答by jitendrapurohit

Alternatively (since Git 1.8.4), it is also possible to just get all the commits which has changed a specific partof a file. You can get this by passing the starting line and the ending line number.

或者(自 Git 1.8.4 起),也可以仅获取已更改文件特定部分的所有提交。您可以通过传递起始行和结束行号来获得它。

The result returned would be the list of commits that modified this particular part. The command goes like:

返回的结果将是修改此特定部分的提交列表。命令如下:

git log --pretty=short -u -L <upperLimit>,<lowerLimit>:<path_to_filename>

where upperLimitis the start_line_numberand lowerLimitis the ending_line_number

哪里upperLimitstart_line_number并且lowerLimitending_line_number

More Info - https://www.techpurohit.com/list-some-useful-git-commands

更多信息 - https://www.techpurohit.com/list-some-useful-git-commands

回答by Roberto

As Hymanrabb1t pointed out, --followis more robust since it continues listing the history beyond renames/moves. So, if you are looking for a file that is not currently in the same path or a file that has been renamed throughout various commits, --follow will track it.

正如 Hymanrabb1t 指出的那样,--follow它更加强大,因为它继续列出重命名/移动之外的历史记录。因此,如果您要查找当前不在同一路径中的文件或已在各种提交中重命名的文件,--follow 将对其进行跟踪。

This can be a better option if you want to visualize the name/path changes:

如果您想可视化名称/路径更改,这可能是一个更好的选择:

git log --follow --name-status -- <path>

But if you want a more compact list with only what matters:

但是如果你想要一个更紧凑的列表,只包含重要的内容:

git log --follow --name-status --format='%H' -- <path>

or even

甚至

git log --follow --name-only --format='%H' -- <path>

The downside is that --followonly works for a single file.

缺点是--follow仅适用于单个文件。

回答by snovelli

If you are trying to --follow a file deletedin a previous commit use

如果您尝试--follow在先前提交中删除的文件,请使用

git log --follow -- filename

回答by Always_Beginner

If you want to view all the commits that changed a file, in all the branches, use this:

如果要查看更改文件的所有提交,请在所有分支中使用以下命令:

git log --follow --all <filepath>

回答by WonderLand

If you want to look for all commits by filenameand not byfilepath, use:

如果要查找所有提交filename不是 byfilepath,请使用:

git log --all -- '*.wmv'