Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Git show history for selected lines?

Tags:

git

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?

like image 485
Borek Bernard Avatar asked May 30 '12 12:05

Borek Bernard


People also ask

How do I see commit history in git?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

Does git save history?

Git stores the complete history of your files for a project in a special directory (a.k.a. a folder) called a repository, or repo.

What is the git history log?

What does git log do? The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA)


2 Answers

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.

like image 188
Borek Bernard Avatar answered Oct 05 '22 02:10

Borek Bernard


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

like image 23
Richard Feraro Avatar answered Oct 05 '22 00:10

Richard Feraro