在单个命令中通过提交更改获取 git diff 的任何方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6910645/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:45:50  来源:igfitidea点击:

Any way to get git diff with commit changes in single command

git

提问by Vinz

Is there any way we can get the details of diff of a file along with it's commit ID details through a single command ? Currently , "git diff tag1..tag2" gives me the entire code change between the two tags but not the commit ID and reasons for commit . When i use " git log " it gives me complete commit change with changes that i'm not concerned with when comparing two tags .

有什么方法可以通过单个命令获取文件差异的详细信息及其提交 ID 的详细信息?目前,"git diff tag1..tag2" 给了我两个标签之间的整个代码更改,但没有提交 ID 和提交原因。当我使用“git log”时,它为我提供了完整的提交更改,其中包含比较两个标签时我不关心的更改。

回答by Gerry

but this change also has a commit ID and commit reason which i want in the same diff file

但是这个更改也有一个提交 ID 和提交原因,我想要在同一个 diff 文件中

I think there is a little confusion here. The git-diff outputs the difference between one commit and another, that difference is not just one commit, it represents a series of commits in the range you specify (662a1fa..64f9766 in the example you gave). So that would be multiple commit IDs and messages, perhaps even thousands if your tags are far enough apart.

我认为这里有点混乱。git-diff 输出一次提交和另一个提交之间的差异,这种差异不仅仅是一次提交,它代表了您指定范围内的一系列提交(在您给出的示例中为 662a1fa..64f9766)。所以这将是多个提交 ID 和消息,如果您的标签相距足够远,甚至可能是数千个。

If git diff were to output all the associated commit messages you would have no good way of telling which part of the diff is associated with each commit ID and commit message. This is why git log exists.

如果 git diff 输出所有关联的提交消息,您将无法判断 diff 的哪一部分与每个提交 ID 和提交消息相关联。这就是 git log 存在的原因。

Git log does display each commit one after another in the range you specify and so that's why it will display commit messages.

Git 日志确实会在您指定的范围内一个接一个地显示每个提交,因此它会显示提交消息。

git-diff shows you the difference between a and z.
git-log shows you the journey a took to become z.

git-diff 显示了 a 和 z 之间的差异。
git-log 向你展示了 a 变成 z 的过程。

With that in mind, I'm guessing this is probably what you are looking for:

考虑到这一点,我猜这可能是您正在寻找的:

git log --color -p --full-diff tag1..tag2

git log --color -p --full-diff tag1..tag2