这个问题需要“行号”。如果您不关心输出中的行号,请参阅此问题和答案。
基本上,我不希望看到更改的内容,只希望看到文件名和行号。
这个问题需要“行号”。如果您不关心输出中的行号,请参阅此问题和答案。
基本上,我不希望看到更改的内容,只希望看到文件名和行号。
当前回答
显示从现在到指定提交之间每个文件中更改的文件名和行数:
git diff --stat <commit-hash>
其他回答
行号是指更改的行数还是实际包含更改的行号?如果你想要更改的行数,使用git diff——stat。这会给你一个像这样的显示:
[me@somehost:~/newsite:master]> git diff --stat
whatever/views/gallery.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
没有选项可以获取更改本身的行号。
我用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中,借助“外部diff”脚本可以做到这一点。
这是一个相当糟糕的问题;这将由您来修复输出您想要的方式。
#! /bin/sh
#
# run this with:
# GIT_EXTERNAL_DIFF=<name of script> git diff ...
#
case $# in
1) "unmerged file $@, can't show you line numbers"; exit 1;;
7) ;;
*) echo "I don't know what to do, help!"; exit 1;;
esac
path=$1
old_file=$2
old_hex=$3
old_mode=$4
new_file=$5
new_hex=$6
new_mode=$7
printf '%s: ' $path
diff $old_file $new_file | grep -v '^[<>-]'
关于“external diff”的详细信息,请参见Git手册中GIT_EXTERNAL_DIFF的描述(大约在700行,非常接近结尾)。
Use:
git diff --name-only
往前走!
在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