Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this is what you want: </p> <pre><code>git rev-list HEAD -- foo.rb | ( while read rev; do git blame -l -L 1000,+5 $rev -- foo.rb | cut -d ' ' -f 1 done; ) | awk '{ if (!h[$0]) { print $0; h[$0]=1 } }' </code></pre> <p>That'll output the the revision number for each commit that has an edit to the lines you've chosen. </p> <p>Here are the steps: </p> <ol> <li><p>The first part <code>git rev-list HEAD -- foo.rb</code> outputs all revisions in which the chosen file is edited. </p></li> <li><p>Each of those revisions then goes into the second part, which takes each one and puts it into <code>git blame -l -L 1000,+5 $rev -- foo.rb | cut -d ' ' -f 1</code>. This is a two-part command. </p> <ol> <li><code>git blame -l -L 1000,+5 $rev -- foo.rb</code> outputs the blame for the chosen lines. By feeding it the revision number, we are telling it to start from that commit and go from there, rather than starting at the head.</li> <li>Since blame outputs a bunch of info we don't need, <code>cut -d ' ' -f 1</code> gives us the first column (the revision number) of the blame output. </li> </ol></li> <li><code>awk '{ if (!h[$0]) { print $0; h[$0]=1 } }'</code> takes out non-adjacent duplicate lines while maintaining the order they appeared in. See <a href="http://jeetworks.org/node/94">http://jeetworks.org/node/94</a> for more info about this command. </li> </ol> <p>You could add a last step here to get prettier output. Pipe everything into <code>xargs -L 1 git log --oneline -1</code> and get the corresponding commit message for the list of revisions. I had a weird issue using this last step where I had to keep pressing next every few revisions that were output. I'm not sure why that was, which is why I didn't include it in my solution. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload