是否有一种方法可以查看分支中哪些文件发生了更改?
当前回答
扩展@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
其他回答
扩展@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
考虑到你在一个特性分支上,你想要检查哪些文件与master…就在这个:
git diff --name-only master
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 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很可能支持这一点。
git show --stat origin/branch_name
这将为您提供在该分支下添加或修改的文件列表。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别