在 Git 中跟踪单个文件的历史记录时如何查看完整提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1974373/
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
How to view complete commits when tracking history of a single file in Git?
提问by Milan Babu?kov
I have a Git repository with about a two years of history in it. 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. I can run gitk with this file as argument:
我有一个大约有两年历史的 Git 存储库。我有一个文件,我希望找到所有提交,以及每个提交:在其中提交的所有其他文件。让我们假设这个文件被命名为 file.txt。我可以用这个文件作为参数运行 gitk:
gitk file.txt
and I do get each commit. However, browsing that tree in gitk only shows changes done to 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.
我确实得到了每个提交。但是,在 gitk 中浏览该树只会显示对 file.txt 所做的更改。我想看看在该提交中更改了哪些其他文件。我可以复制粘贴每个提交 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?
我注意到屏幕右下角的“评论”部分是空的(只显示文本“评论”)。也许可以在那里显示文件列表?
采纳答案by iamamac
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 noarguments, find commit "touching path" file.txt, and the commit contains that file will be bold. And you can use the "up" and "down" buttons to traverse through it.
如果你必须看到它在gitk,调用它没有参数,发现犯“感人路径” file.txt的,并提交包含该文件将是大胆的。您可以使用“向上”和“向下”按钮来遍历它。
回答by ack
You can actually have '--full-diff' functionality in gitk, just not directly from the command line. Just do the following:
实际上,您可以在 gitk 中使用“--full-diff”功能,而不能直接从命令行使用。只需执行以下操作:
- Start gitk the usual way, e.g.:
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
- Click "Apply" or hit [F5].
- 以通常的方式启动 gitk,例如:
gitk file.txt
- 从菜单中选择“查看 -> 编辑视图...”。确认您正在编辑“命令行”视图。
- 在“git log 的附加参数”旁边的编辑框中,键入
--full-diff
- 单击“应用”或按 [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 不允许你从命令行使用它对我来说是个谜,因为它是一个非常有用的选项。