简体   繁体   English

如何在Git中跟踪单个文件的历史记录时查看完整的提交?

[英]How to view complete commits when tracking history of a single file in Git?

I have a Git repository with about a two years of history in it. 我有一个大约有两年历史的Git存储库。 I have single file in it, for which I wish to find all the commits, and for each commit: all the other files that were committed in it. 我有单个文件,我希望找到所有提交,并为每个提交:在其中提交的所有其他文件。 Let's assume this file is named file.txt. 我们假设这个文件名为file.txt。 I can run gitk with this file as argument: 我可以用这个文件作为参数运行gitk:

gitk file.txt

and I do get each commit. 而我确实得到了每一次提交。 However, browsing that tree in gitk only shows changes done to file.txt. 但是,在gitk中浏览该树只会显示对file.txt所做的更改。 I'd like to see what other files were changed in that commit. 我想看看那个提交中有哪些其他文件被更改了。 I can copy paste each commit SHA1 and display it, but there are over hundred of commits related to this file. 我可以复制粘贴每个提交SHA1并显示它,但有超过一百个与此文件相关的提交。

I notice that "comments" section in bottom-right part of screen is empty (only shows text "Comments"). 我注意到屏幕右下角的“评论”部分为空(仅显示文本“评论”)。 Maybe a list of files could be shown there? 也许可以在那里显示文件列表?

In the command line, 在命令行中,

git log -p --full-diff file.txt

will output what you want. 将输出你想要的。

If you must see it in gitk, invoke it with no arguments, find commit "touching path" file.txt, and the commit contains that file will be bold. 如果你必须gitk看到它, 带参数调用它,发现犯“感人路径” file.txt的,并提交包含该文件将是大胆的。 And you can use the "up" and "down" buttons to traverse through it. 您可以使用“向上”和“向下”按钮遍历它。

You can actually have '--full-diff' functionality in gitk, just not directly from the command line. 实际上你可以在gitk中使用'--full-diff'功能,而不是直接从命令行。 Just do the following: 只需执行以下操作:

  • Start gitk the usual way, eg: gitk file.txt 以通常的方式启动gitk,例如: gitk file.txt
  • Select 'View -> Edit view...' from the menu. 从菜单中选择“查看 - >编辑视图...”。 Verify that you are editing the 'Command line' view. 确认您正在编辑“命令行”视图。
  • In the edit box next to "Additional arguments to git log", type --full-diff 在“git log的附加参数”旁边的编辑框中,键入--full-diff
  • Click "Apply" or hit [F5]. 单击“应用”或按[F5]。

That should do it. 应该这样做。 Why gitk doesn't allow you to use this from the command line is a mystery to me, for it is a very useful option. 为什么gitk不允许你从命令行使用它对我来说是一个谜,因为它是一个非常有用的选项。

Another solution from the mailing list dated far back in 2008 : 邮件列表的另一个解决方案可追溯到2008年

Try turning off the option "Limit diffs to listed paths" in the preferences menu (or adding "set limitdiffs 0" to your ~/.gitk). 尝试关闭首选项菜单中的“限制差异到列出的路径”选项(或将“set limitdiffs 0”添加到〜/ .gitk)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM