这个问题需要“行号”。如果您不关心输出中的行号,请参阅此问题和答案。


基本上,我不希望看到更改的内容,只希望看到文件名和行号。


当前回答

最干净的输出,也就是文件名/路径

git diff-tree --no-commit-id --name-only -r

其他回答

在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

Use:

git diff master --compact-summary

输出结果为:

 src/app/components/common/sidebar/toolbar/toolbar.component.html   |  2 +-
 src/app/components/common/sidebar/toolbar/toolbar.component.scss   |  2 --

这正是你所需要的。与从远程进行提交或提取新提交时的格式相同。

PS:奇怪的是没有人这样回答。

行号是指更改的行数还是实际包含更改的行号?如果你想要更改的行数,使用git diff——stat。这会给你一个像这样的显示:

[me@somehost:~/newsite:master]> git diff --stat
 whatever/views/gallery.py |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

没有选项可以获取更改本身的行号。

显示从现在到指定提交之间每个文件中更改的文件名和行数:

git diff --stat <commit-hash>

最干净的输出,也就是文件名/路径

git diff-tree --no-commit-id --name-only -r