Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line history viewer - Git

I wondered if any of you knew of a tool that would allow me to select a line in my code and then view a list view of the history of that line on a commit-by-commit basis.

Does anyone know of such a tool?

like image 484
David.LPower Avatar asked Mar 27 '13 14:03

David.LPower


People also ask

How can I see my line history?

Press Ctrl+K L , or right-click the tab title then click "Show Line History" to enter the "Line History" view. In the "Line History" view: Press [ or ] to check out previous, or next versions. Press d to toggle deleted lines.

How can I see previous commits?

If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

How do I view line history in Intellij?

Review file history Select Git | Show History from the main VCS menu or from the context menu of the selection. The History tab is added to the Git tool window showing the history for the selected file and allowing you to review and compare its revisions.


7 Answers

Maybe annotations in IntelliJ IDEA is that you are looking for:

the left gutter with enabled annotations

Showing and hiding annotations

  1. Open the desired file in the editor.
  2. To show annotations, right-click the left gutter, and select Annotate:
    context menu
  3. To hide annotations, right-click the annotations gutter, and choose Close Annotations.
like image 145
Lu55 Avatar answered Oct 01 '22 06:10

Lu55


I know only the IntelliJ IDEA "Viewing Changes History for Selection" feature.

You could also try to use several git blame commands to iterate over history of a fragment.

like image 22
kan Avatar answered Oct 01 '22 06:10

kan


If you would like to view inline such information then you may add GitToolBox plugin. Live example on YT

Example view: enter image description here

How to setup: enter image description here enter image description here

like image 32
Dawid Avatar answered Oct 03 '22 06:10

Dawid


git log (docs)

git-log shows commit logs.

Usage example

You can specify -L option to trace the evolution of the line range given by ",". You can specify this option more than once.

git log -L 40,50:foo.txt
like image 35
naXa Avatar answered Oct 03 '22 06:10

naXa


If you are using IntelliJ then, its annotation feature provides an option to do the annotation on previous revision. Using this option you can go back to the history of that line.

Find below screen-shot which shows, This option and its available in the community edition as well.

enter image description here

like image 23
Amit Avatar answered Oct 03 '22 06:10

Amit


As suggested in one of the comments in Can Git show history for selected lines?

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

more info: Every line of code is always documented.

like image 28
Snger Avatar answered Oct 01 '22 06:10

Snger


In IntelliJ, you can use show history for selection in the git submenu after selecting a line/ multiple lines.

enter image description here

like image 36
Vishrant Avatar answered Oct 03 '22 06:10

Vishrant