是否有一种方法可以列出更改特定文件的所有提交?


当前回答

获取特定文件的所有提交:

git rev-list HEAD—oneline FileName

例如

git rev-list HEAD—oneline index.html

输出

7a2bb2f update_index_with_alias
6c03e56 update_changes
e867142 Revert "add_paragraph"

参见gif图片

其他回答

——follow适用于特定的文件

git log --follow -- filename

与给出的其他解的区别

注意,其他解决方案包括git日志路径(没有——follow)。如果你想跟踪目录中的变化,但是当文件被重命名时(因此使用——follow filename),这种方法很方便。

# Shows commit history with patch
git log -p -<no_of_commits> --follow <file_name>

# Shows brief details like "1 file changed, 6 insertions(+), 1 deletion(-)"
git log --stat --follow <file_name>

参考

Git日志路径应该做你想做的。从git日志手册页:

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

如果你想查看所有修改文件的提交,在所有分支中,使用这个:

git log --follow --all <filepath>

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

以下是我通过摆弄gitk编辑视图选项得到的结果。这显示了一个文件的所有提交,而不考虑分支、本地、reflog和远程。

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

它也适用于git日志:

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