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


当前回答

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

参考

正如jackrabb1t指出的那样,——follow更加健壮,因为它继续列出重命名/移动之外的历史记录。因此,如果你正在寻找一个当前不在同一路径上的文件,或者一个在多次提交中被重命名的文件,——follow将跟踪它。

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

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

但如果你想要一个更紧凑的清单,只列出重要的事情:

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

甚至

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

缺点是—follow只适用于单个文件。

在Linux上,你可以使用gitk。

可以使用“sudo apt-get install git-gui gitk”进行安装。它可以通过“gitk <Filename>”来查看特定文件的提交。

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

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图片