使用行号的Git diff(带行号的Git日志) [英] Git diff with line numbers (Git log with line numbers)

查看:302
本文介绍了使用行号的Git diff(带行号的Git日志)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做一个 git diff 或一个 git log -p 时,如何获得源文件与输出内联?



我试图查看它 man git-diff | grep行号,我尝试了谷歌搜索,但没有得到任何快速消息。

你不能用 git diff

获得可读的行数目前没有任何选项可以显示行号垂直与 git diff



统一差异格式



这些信息可以在(c)hunk头文件中找到差异中的每个变化,但它只是在统一格式 @ -start,count + start,count @@

文件的原始状态用 - ,新状态用 + 表示(它们并不意味着大块头中的添加和删除。 code> start 表示每个版本文件的起始行号, count 表示从起点开始包括多少行。

示例



  diff --git a / osx / .gitconfig b / osx / .gitconfig 
索引4fd8f04..fcd220c 100644
- - a / osx / .gitconfig
+++ b / osx / .gitconfig
@@ -11,7 +11,7 @@< ==这里!
[颜色分支]
上游=青色
[颜色差异]
- 元=黄色
+元=青色
素色=白色暗淡的
旧的=红色的粗体
新的=绿色的粗体

/ p>

  @@ -11,7 +11,7 @@ 

表示该文件的前一版本从第11行开始,包含7行:

  11 [颜色分支] 
12上游=青色
13 [颜色差异]]
14 - 元=黄色
14 + meta =青色
15 plain = white dim
16 old =红色粗体
17新=绿色粗体

,而该文件的下一个版本也从第11行开始,并且还包含7行。

统一差异格式不适用于人类消费



正如您可以说的那样,统一差异格式并不容易弄清行数(a至少如果你不是机器)。如果你真的需要你可以阅读的行号,你需要使用一个差异化工具来显示它们。



附加阅读




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 man git-diff | grep "line numbers" and I tried googling but got nothing quickly.

解决方案

You can't get human-readable line numbers with git diff

There aren't currently any options to get line-numbers displayed vertically on the side with git diff.

Unified-diff format

That information is available in the (c)hunk headers for each change in the diff though, it's just in unified-diff format:

@@ -start,count +start,count @@

The original state of the file is represented with -, and the new state is represented with + (they don't mean additions and deletions in the hunk header. start represents the starting line number of each version of the file, and count represents how many lines are included, starting from the start point.

Example

diff --git a/osx/.gitconfig b/osx/.gitconfig
index 4fd8f04..fcd220c 100644
--- a/osx/.gitconfig
+++ b/osx/.gitconfig
@@ -11,7 +11,7 @@ <== HERE!
 [color "branch"]
        upstream = cyan
 [color "diff"]
-       meta = yellow
+       meta = cyan
        plain = white dim
        old = red bold
        new = green bold

The hunk header

@@ -11,7 +11,7 @@

says that the previous version of the file starts at line 11, and includes 7 lines:

11  [color "branch"]
12         upstream = cyan
13  [color "diff"]
14 -       meta = yellow
14 +       meta = cyan
15         plain = white dim
16         old = red bold
17         new = green bold

while the next version of the file also starts at line 11, and also includes 7 lines.

Unified-diff format isn't really for human consumption

As you can probably tell, unified-diff format doesn't make it easy to figure out line numbers (at least if you're not a machine). If you really want line numbers that you can read, you'll need to use a diffing tool that will display them for you.

Additional Reading

这篇关于使用行号的Git diff(带行号的Git日志)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆