Find a merge commit that changed a given row?

We are using the git -flow style workflow, and we want to know which pull request included the changes to this line of code.

Suppose we have the following story:

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

My transfer request was merged in h with the commit message "Merge Merge Request No. 123".

If I execute git fault on lines of code added to a stretch request, it shows me e , not 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 

How can I find a merge commit for a given line of code in git?

(Note that this is different from this related question , as I start with lines of code, not commit).

+5
source share
1 answer

Merge negotiation will only appear in git -blame if you resolved the conflict in that commit.

For a normal merge without conflict, h will never appear in the git fault, since it has not changed in any line of code and just merged g and f.

So what you can achieve in 2 steps

  • First, find out which commit has affected the line of code that interests you. This can be achieved using the git blame -L option (included with git 1.8.4). Give a range of 10+ lines, as the line number would probably change.

    $ git blame -L200, + 10 - filename.ext

  • Find the first command merge after the commit found in step 1. So, you will need to first find which commit affected the line of code you are interested in. This can be achieved, as indicated in the Find merge command, which includes a specific commit.

+2
source

Source: https://habr.com/ru/post/1214314/


All Articles