Git diff with line numbers (Git log with line numbers)

后端 未结 9 878
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 18:57

When I do a git diff or a git log -p, how do I get line numbers of the source file(s) inlined with the output?

I tried to look it up

9条回答
  •  猫巷女王i
    2020-11-29 19:31

    You can use git difftool to do the diff with an external editor that will display line numbers. Here's how to do it with vim / vimdiff:

    1. Set vimdiff as git's difftool:

      git config --global diff.tool vimdiff
      
    2. Configure ~/.vimrc to automatically show line numbers when using vimdiff:

      if &diff
          set number
      endif
      
    3. Run git difftool, which will use vimdiff with line numbers:

      git difftool
      

提交回复
热议问题