Borek Bernard
Borek Bernard

Reputation: 53201

Can Git show history for selected lines?

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?

Upvotes: 21

Views: 11877

Answers (6)

soung
soung

Reputation: 1614

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

Upvotes: 2

konradwww
konradwww

Reputation: 691

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

Upvotes: 1

Snger
Snger

Reputation: 1384

git show $(git blame XYZ -L 250,260 | awk '{print $1}')

Every line of code is always documented. via @mislav

Upvotes: 7

Richard Feraro
Richard Feraro

Reputation: 477

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

Upvotes: 18

Borek Bernard
Borek Bernard

Reputation: 53201

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.

Upvotes: 18

Sebi
Sebi

Reputation: 8953

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.

Upvotes: 2

Related Questions