检查由一组提交引起的差异
我想查看只有两个提交的差异。
例如,
$ git log --oneline
0ff4567 fix bug #1, now really really really
1ff4567 fix bug #1 really
2ff4567 fix bug #2
3ff4567 fix bug #3
4234567 refactor code
5ff4567 fix bug #1
6234567 fix bug #4
我只想查看与 bug #1 相关的提交,即提交 0ff4567
、1ff4567
、5ff4567
。
我不关心其余提交的差异。
有没有简单的方法可以做到这一点?
更新:我知道相关提交的列表。给定这个列表,我想获得一个更容易检查的差异。
I want to view the diff of only two commits.
For instance
$ git log --oneline
0ff4567 fix bug #1, now really really really
1ff4567 fix bug #1 really
2ff4567 fix bug #2
3ff4567 fix bug #3
4234567 refactor code
5ff4567 fix bug #1
6234567 fix bug #4
I want to view only the commits relevant to bug #1, that is, commits 0ff4567
,1ff4567
,5ff4567
.
I don't care about the diffs of the rest of the commits.
Is there an easy way to do that?
Update: I know the list of relevant commits. Given this list, I want to get a single diff, which is easier to review.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以对
git log
使用--grep
选项,该选项仅输出带有与特定正则表达式匹配的日志消息的提交。在您的情况下,您可以这样做:...如果您想查看每个提交引入的补丁,当然,您应该这样做:
在下面的注释中,您解释说您确实想要一个补丁作为输出,它代表这三个提交引入的补丁的累积效果。在这种情况下,您可以尝试以下方法之一:
combinediff
工具来组合差异。 (这可能不起作用,具体取决于中间提交的更改。)为了对后一个选项进行一些扩展,此脚本基于 ("super-kludgy") 示例 by Jefromi:
...您可以将其调用为:
...然后将创建分支
tmp-branch,变基回到与
bug #1
匹配的第一个提交的父级,仅选择与bug #1
匹配的提交,并压缩除第一个之外的所有提交。 (您可能必须修复一些冲突,并为压缩的提交提供提交消息。)如果成功,那么您可以执行以下操作:... 查看组合补丁。我并不认真推荐任何人使用这个脚本,但我认为这是一种有趣且古怪的方式来做你想做的事:)
You can use the
--grep
option togit log
, which only outputs commits with log messages that match a particular regular expression. In your case you could do:... if you want to see the patches introduced by each of those commits, of course, you should do:
In the comments below, you explain that you really want one patch as output, which represents the cumulative effect of the patches introduce by those three commits. In that case, you could try one of the following:
combinediff
tool from patchutils to combine the diffs. (This may not work, depending on what the intermediate commits have changed.)GIT_EDITOR
environment variable) to reorder and squash the commits.To expand a bit on the latter option, this script is based on a ("super-kludgy") example by Jefromi:
... which you might invoke as:
... which will then create the branch
tmp-branch
, rebase back to the parent of the first commit that matchesbug #1
, only picking commits that matchbug #1
and squash all but the first one. (You may have to fix some conflicts, and provide a commit message for the squashed commits.) If that succeeds, then you can just do:... to see the combined patch. I don't seriously recommend anyone use this script, but it's a fun and hacky way of doing what you want, I think :)
您可以使用 git log --grep=fix1 (如 Git 参考 所示) )以便隔离相关提交,然后对每个提交执行 git show。
请参阅“git commit 与其父级的 diff 的简写?”。
将这些补丁合并为一个差异并不简单,正如 Jefromi 在“带有作者过滤器的 git diff"。
在您的情况下,可能的(相当麻烦)的解决方案应该类似于“提取相关更改代码审查”:
因此:专用的
fix1_review
分支是可能的,但这仍然是半自动设置(因为您必须解决可能的冲突)。You could use
git log --grep=fix1
(as show in Git reference) in order to isolate the relevant commit, and then perform agit show <commit>
for each commit.See "Shorthand for diff of git commit with its parent?".
Combining those patches as a single diff isn't trivial, as Jefromi explains in "git diff with author filter".
In your case, a possible (quite cumbersome) solution should be similar to "Extract relevant changes for code review":
So: a dedicated
fix1_review
branch is possible, but that remains a semi-automated setup (as you have to solve possible conflicts).