21

I have a large file where, somewhere in the middle, there is a function that I know has been modified several times. git annotate or blame will show the most recent commit for each line but if I'm right, it will show only the most recent one, not a list of other commits that affected that line before.

So is there a command in Git where I could say something like show me commits that affected lines 250..260 in file XYZ?

Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
  • not line, but git log … - show only commits that affect the specified paths. maybe it helps – 0xAX May 30 '12 at 12:49
  • 1
    Possible duplicate of [how do I view the change history of a method/function?](http://stackoverflow.com/q/4781405/11343) – CharlesB May 30 '12 at 12:52
  • Thanks @CharlesB, I found some good advice there and posted it as an answer here. – Borek Bernard May 30 '12 at 13:07
  • 1
    possible duplicate of [Retrieve the commit log for a specific line in a file?](http://stackoverflow.com/questions/8435343/retrieve-the-commit-log-for-a-specific-line-in-a-file) – László Papp Oct 10 '14 at 08:25

6 Answers6

18

As suggested in one of the comments in Git - how do I view the change history of a method/function?, doing

git gui blame <file>

and then right-clicking a line and selecting Blame Parent Commit does what I need.

Community
  • 1
  • 1
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
18

phpStorm can do this. Select the lines -> right-click -> Git -> Show History for Selection

Richard Feraro
  • 467
  • 4
  • 9
7
git show $(git blame XYZ -L 250,260 | awk '{print $1}')

Every line of code is always documented. via @mislav

Community
  • 1
  • 1
Snger
  • 1,374
  • 19
  • 23
2

I think that's not possible. You will need to write a script around git blame. You can find a bash example of such a script on GitHub.

Sebi
  • 8,323
  • 6
  • 48
  • 76
2

Select line -> Right-click->Git->Annotate

konradwww
  • 693
  • 7
  • 16
1

this fonctionnality made me switch to IntelliJ Idea. With IntelliJ you can select lines, right clic -> git -> Show history for selection enter image description here

soung
  • 1,411
  • 16
  • 33