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


当前回答

2020年11月更新:

要获得当前分支中修改(并提交!)的文件列表,您可以使用使用标准git的最短控制台命令:

Git diff -name-only master…


If your local "master" branch is outdated (behind the remote), add a remote name (assuming it is "origin"): git diff --name-only origin/master... If you want to include uncommitted changes as well, remove the ...: git diff --name-only master If you use different main branch name (eg: "main"), substitute it: git diff --name-only main... If your want to output to stdout (so its copyable): git diff --name-only master... | cat If your want filenames to be clickable in VSCode terminal no matter what folder you are running this command from, add --relative: git diff --name-only --relative master... | cat


每个非常好的详细解释不同的选项https://blog.jpalardy.com/posts/git-how-to-find-modified-files-on-a-branch/

其他回答

不知道为什么,没人提吉特。参见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等等)

下面的批处理文件是基于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)"

如果真能这么简单呢?

git changed

如果您愿意假设主分支被称为“master”,并且您从master创建其他分支,那么您可以将这个别名添加到~/。Gitconfig文件使它变得简单:

cbranch = !"git branch | grep '*' | cut -f2 -d' '"
changed = !"git diff --name-only $(git cbranch) $(git merge-base $(git cbranch) master)"

这些假设在大多数情况下适用于大多数人,但你必须意识到你在做这些假设。

此外,您必须使用支持$()的shell。您的shell很可能支持这一点。

2020年11月更新:

要获得当前分支中修改(并提交!)的文件列表,您可以使用使用标准git的最短控制台命令:

Git diff -name-only master…


If your local "master" branch is outdated (behind the remote), add a remote name (assuming it is "origin"): git diff --name-only origin/master... If you want to include uncommitted changes as well, remove the ...: git diff --name-only master If you use different main branch name (eg: "main"), substitute it: git diff --name-only main... If your want to output to stdout (so its copyable): git diff --name-only master... | cat If your want filenames to be clickable in VSCode terminal no matter what folder you are running this command from, add --relative: git diff --name-only --relative master... | cat


每个非常好的详细解释不同的选项https://blog.jpalardy.com/posts/git-how-to-find-modified-files-on-a-branch/

令人惊讶的是,到目前为止还没有人这么说!

git diff main...branch

所以只在分支上看到变化

检查当前分支的使用情况

git diff main...

感谢jqr

这是简称

git diff $(git merge-base main branch) branch

所以合并基(分支之间最近的共同提交)和分支尖端

此外,使用origin/main而不是master将有助于防止本地main过期