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


当前回答

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

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

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

其他回答

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

git diff --name-only master

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

git diff main...branch

所以只在分支上看到变化

检查当前分支的使用情况

git diff main...

感谢jqr

这是简称

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

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

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

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

接受的答案- git diff——name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>) -非常接近,但我注意到它的删除状态是错误的。我在分支中添加了一个文件,但是这个命令(使用——name-status)给了我删除的文件“a”状态和我添加的文件“D”状态。

我不得不使用这个命令:

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

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/