我们使用的是git-flow样式的工作流程,我们想找出哪个 pull 请求包括对给定代码行的更改。

假设我们有以下历史记录:

       c---e---g
      /         \
-a---b---d---f---h--- master

我的 pull 请求已在h中与提交消息“merge pull 请求#123” merge 。

如果我对pull请求中添加的代码行进行git责备,它将显示e而不是h
12345678 (Wilfred Hughes           2015-02-02 15:22:40 +0000 402) # Some old code
e        (Wilfred Hughes           2015-02-12 15:22:40 +0000 402) # Added in the PR, line 1
e        (Wilfred Hughes           2015-02-12 15:22:40 +0000 403) # Added in the PR, line 2
56789012 (Wilfred Hughes           2015-02-26 17:24:18 +0000 404) # More old code

如何在git中找到给定代码行的 merge 提交?

(请注意,这与this related question不同,因为我从代码行而不是提交开始)。

最佳答案

如果您已解决提交中的冲突,则 merge 提交只会出现在git-blame中。

对于没有冲突的普通 merge ,h永远不会出现在git blame中,因为它在任何代码行中都没有变化,而只是 merge 了g和f。

因此,您想要的东西可以分两个阶段实现

  • 首先找到您感兴趣的提交受影响的代码行。这可以通过git blame -L选项(在git 1.8.4中提供)来实现。给出10行以上的范围,因为确切的行号可能已更改。

    $ git blame -L200,+ 10-filename.ext
  • 在步骤1中找到的提交之后找到第一个 merge 提交
    因此,您必须首先找到哪个提交会影响您感兴趣的代码行。这可以通过Find merge commit which include a specific commit
  • 中的回答来实现

    关于git - 找到修改给定行的 merge 提交?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28762882/

    10-10 00:41
    查看更多