是否有一种方法可以查看分支中哪些文件发生了更改?


当前回答

考虑到你在一个特性分支上,你想要检查哪些文件与master…就在这个:

git diff --name-only master

其他回答

git show --stat origin/branch_name

这将为您提供在该分支下添加或修改的文件列表。

扩展@twalberg和@iconoclast,如果你因为任何原因使用cmd,你可以使用:

FOR /F "usebackq" %x IN (`"git branch | grep '*' | cut -f2 -d' '"`) DO FOR /F "usebackq" %y IN (`"git merge-base %x master"`) DO git diff --name-only %x %y

不知道为什么,没人提吉特。参见https://stackoverflow.com/a/424142/1657819

Git-tree是首选,因为它是一个管道命令;应该是程序化的(而且可能更快)

(假设基础分支是master)

git diff-tree --no-commit-id --name-only -r master..branch-name

然而,这将显示分支中所有受影响的文件,如果你只想看到显式修改的文件,你可以使用——diff-filter:

git diff-tree --no-commit-id --name-only -r master..branch-name --diff-filter=M

也可以使用——name-status来代替——name-only来查看文件的状态(A/M/D等等)

@Marco Ponti的另一个答案,避免结帐:

git diff --name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>)

如果您的特定shell不理解$()结构,则使用反引号代替。

下面的批处理文件是基于twalberg的回答,但可以在Windows中工作:

@ECHO OFF
C:                               :: <== OR USE A DIFFERENT DRIVE
CD \path\to\where\git\files\are  :: <== CHANGE TO THE ACTUAL PATH
SET /p b="Enter full path of an ALREADY MERGED branch to compare with origin/master: "
bash --login -i -c "git diff --name-only %b% $(git merge-base %b1% origin/drop2/master)"
PAUSE

上面假设主分支是origin/master,并且在安装git时包含了git bash(它的位置在path环境中)。我实际上需要使用配置的diff工具(kdiff3)来显示实际的差异,因此替换了上面的以下bash命令:

bash --login -i -c "git difftool --dir-diff %b% $(git merge-base %b1% origin/drop2/master)"