这个问题需要“行号”。如果您不关心输出中的行号,请参阅此问题和答案。
基本上,我不希望看到更改的内容,只希望看到文件名和行号。
这个问题需要“行号”。如果您不关心输出中的行号,请参阅此问题和答案。
基本上,我不希望看到更改的内容,只希望看到文件名和行号。
当前回答
行号是指更改的行数还是实际包含更改的行号?如果你想要更改的行数,使用git diff——stat。这会给你一个像这样的显示:
[me@somehost:~/newsite:master]> git diff --stat
whatever/views/gallery.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
没有选项可以获取更改本身的行号。
其他回答
在Windows上,这将过滤Git输出到文件和更改的行号:
(git diff -p——stat) | findstr "@@——git"
diff --git a/dir1/dir2/file.cpp b/dir1/dir2/file.cpp
@@ -47,6 +47,7 @@ <some function name>
@@ -97,7 +98,7 @@ <another functon name>
要从中提取文件和更改的行需要更多的工作:
/ f”令牌= 3,4 * delims = - +”% f(“^ (git diff - p - stat。^)^ |中^“@@——git ^”)做@echo % f
a/dir1/dir2/file.cpp
47,7
98,7
行号是指更改的行数还是实际包含更改的行号?如果你想要更改的行数,使用git diff——stat。这会给你一个像这样的显示:
[me@somehost:~/newsite:master]> git diff --stat
whatever/views/gallery.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
没有选项可以获取更改本身的行号。
我最喜欢的:
git diff --name-status
前置文件状态,例如:
A new_file.txt
M modified_file.txt
D deleted_file.txt
2)如果你想要统计数据,那么:
git diff --stat
将显示如下内容:
new_file.txt | 50 +
modified_file.txt | 100 +-
deleted_file | 40 -
3)最后,如果你真的只想要文件名:
git diff --name-only
将简单地显示:
new_file.txt
modified_file.txt
deleted_file
我用grep作为初始解。
$ git diff | grep -A2 -- '---'
输出示例:
--- a/fileA.txt
+++ b/fileA.txt
@@ -0,0 +1,132 @@
--
--- a/B/fileC.txt
+++ b/B/fileC.txt
@@ -33663,3 +33663,68800 @@ word_38077.png,Latin
--
--- a/D/fileE.txt
+++ b/D/fileE.txt
@@ -17998,3 +17998,84465 @@ word_23979.png,Latin
--
--- a/F
+++ b/F
@@ -1 +1 @@
也许你可以看到彩色的输出。它可以帮助您轻松地阅读输出。
在git 2.17.1版本中,没有内置标志来实现这一目的。
下面是一个从统一的diff中过滤出文件名和行号的示例命令:
git diff --unified=0 | grep -Po '^diff --cc \K.*|^@@@( -[0-9]+,[0-9]+){2} \+\K[0-9]+(?=(,[0-9]+)? @@@)' | paste -s -d':'
例如,统一的差异:
$ git diff --unified=0
diff --cc foobar
index b436f31,df63c58..0000000
--- a/foobar
+++ b/foobar
@@@ -1,2 -1,2 +1,6 @@@ Line abov
++<<<<<<< HEAD
+bar
++=======
+ foo
++>>>>>>> Commit message
会导致:
❯ git diff --unified=0 | grep -Po '^diff --cc \K.*|^@@@( -[0-9]+,[0-9]+){2} \+\K[0-9]+(?=(,[0-9]+)? @@@)' | paste -s -d':'
foobar:1
查询普通grep匹配结果中命令的输出信息。
$ git diff --unified=0 | grep -Po '^diff --cc \K.*|^@@@( -[0-9]+,[0-9]+){2} \+\K[0-9]+(?=(,[0-9]+)? )| @@@.*' | sed -e '0~3{s/ @@@[ ]\?//}' | sed '2~3 s/$/\n1/g' | sed "N;N;N;s/\n/:/g"
foobar:1:1:Line abov
grep -Po '^diff --cc \K.*|^@@@( -[0-9]+,[0-9]+){2} \+\K[0-9]+(?=(,[0-9]+)? ): Match filename from diff --cc <filename> OR Match line number from @@@ <from-file-range> <from-file-range> <to-file-range> OR Match remaining text after @@@. sed -e '0~3{s/ @@@[ ]\?//}': Remove @@@[ ]\? from every 3rd line to get the optional 1 line context before ++<<<<<<< HEAD. sed '2~3 s/$/\n1/g': Add \n1 every 3 lines between the 2nd and 3rd line for the column number. sed "N;N;N;s/\n/:/g": Join every 3 lines with a :.