2

I searched everywhere, only to find a very similar question but about GitHub rather than Git on Stack Overflow.

I need a link locally referring to a line in a branch in a file and in a repository. I know I can do it by using a global mark, for instance in Vim, but can I skin a cat in a Git way? I only know a little about the plumbing commands of Git. Maybe in repository/branch/file/line form?

Community
  • 1
  • 1
Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66

1 Answers1

2

You could use git show and output it to vim along with a specific line number like the following:

git show branch_name:your_file | vim - +45

or use a specific hash:

git show b4524bcd:your_file | vim - +45
fpietka
  • 1,027
  • 1
  • 10
  • 23
  • If you only want to print a specific line number you can pipe it to `sed -n 45p` instead of vim. – che Sep 27 '15 at 12:46
  • you can specify a directory before the `show` part: `git --git-dir=my_folder/.git show ...`. Just keep in mind you'll have to target `.git` directory within your project. – fpietka Sep 27 '15 at 13:08