首页 文章

列出特定文件的所有提交

提问于
浏览
595

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

15 回答

  • 34

    正如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 仅适用于单个文件 .

  • 117
    gitk <path_to_filename>
    

    假设已经安装了包“gitk” .

    如果未安装,请执行以下操作:

    sudo apt-get install gitk
    

    然后尝试上面的命令 . 它适用于Linux ......如果Linux用户需要GUI,它可能会有所帮助 .

  • 9

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

    git log --follow --all <filepath>
    
  • 32

    它应该像 git log <somepath> 一样简单;检查联机帮助页( git-log(1) ) .

    我个人喜欢使用 git log --stat <path> 所以我可以看到每个提交对文件的影响 .

  • 3

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

    git log -p filename
    
  • 829

    git log path 应该做你想要的 . 来自git log man

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

    或者(从Git 1.8.4开始),也可以只获取已更改文件特定 part 的所有提交 . 您可以通过传递起始行和结束行号来获得此结果 .

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

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

    其中 upperLimitstart_line_numberlowerLimitending_line_number

  • 31
    # 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>
    

    Reference

  • 9

    如果要查找 filenamenot by filepath 的所有提交,请使用:

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

    在Linux上,你可以使用gitk .

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

  • 4

    如果您在之前的提交使用中尝试 --follow a file deleted

    git log --follow -- filename
    
  • 2

    --follow 适用于特定文件

    git log --follow -- filename
    

    Difference to other solutions given

    请注意,其他解决方案包括 git log path (不包含 --follow ) . 如果你想跟踪例如,这种方法很方便 directory 中的更改,但在重命名文件时发生故障(因此使用 --follow filename ) .

  • 0

    使用 git log --all <filename> 查看在所有分支中影响 <filename> 的提交 .

  • 0

    如果您希望查看更改特定文件的提交中所做的所有更改(而不仅仅是对文件本身的更改),则可以传递 --full-diff

    git log -p --full-diff [branch] -- <path>
    
  • 2

    我一直在密切关注这一点,所有这些答案似乎并没有真正向我展示所有分支机构的所有提交 .

    这是我通过搞乱gitk编辑视图选项而想出的 . 无论分支,本地,reflog和远程如何,这都显示 all the commits for a file .

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

相关问题