git 获取git分支中所有修改过的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10641361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get all files that have been modified in git branch
提问by Raif
Is there a way to see what files have changed in a branch?
有没有办法查看分支中哪些文件发生了变化?
采纳答案by twalberg
An alternative to the answer by @Marco Ponti, and avoiding the checkout:
@Marco Ponti 答案的替代方法,并避免结帐:
git diff --name-only <notMainDev> $(git merge-base <notMainDev> <mainDev>)
If your particular shell doesn't understand the $() construct, use back-ticks instead.
如果您的特定 shell 不理解 $() 构造,请改用反引号。
回答by Marco Ponti
All you have to do is the following:
您所要做的就是以下几点:
git checkout <notMainDev>
git diff --name-only <mainDev>
This will show you only the filenames that are different between the two branches.
这将仅显示两个分支之间不同的文件名。
回答by exussum
amazed this has not been said so far!
惊讶这还没说呢!
git diff master...branch
So see the changes only on branch
所以只看到变化 branch
To check the current branch use
检查当前分支使用
git diff master...
Thanks to jqr
感谢 jqr
This is short hand for
这是简写
git diff $(git merge-base master branch) branch
so the merge base (the most recent common commit between the branches) and the branch tip
所以合并基础(分支之间最近的常见提交)和分支提示
Also using origin/master instead of just master will help in case your local master is dated
如果您的本地主人过时,也使用 origin/master 而不是 master 会有所帮助
回答by lukiller
I can't believe there are so many ways to do this. I use whatchanged as someone posted before, just with the following arguments:
我不敢相信有这么多方法可以做到这一点。我使用 whatchanged 作为之前发布的某人,只是使用以下参数:
git whatchanged --name-only --pretty="" origin..HEAD
This just lists the filenames, and only the ones that changed on the current branch.
这仅列出文件名,并且仅列出在当前分支上更改的文件名。
回答by Yep_It's_Me
I really liked @twalberg's answer but I didn't want to have to type the current branch name all the time. So I'm using this:
我真的很喜欢@twalberg 的回答,但我不想一直输入当前的分支名称。所以我正在使用这个:
git diff --name-only $(git merge-base master HEAD)
回答by chalasr
git whatchanged
seems to be a good alternative.
git whatchanged
似乎是一个不错的选择。
回答by Rajesh Dusa
git diff --name-only master...branch-name
to which we want to compare.
我们想要比较的。
回答by iconoclast
What if it could be as easy as this?
如果可以这么简单呢?
git changed
If you're willing to assume that the main branch is called "master", and that you create your other branches from master, then you can add this alias to your ~/.gitconfig
file to make it that easy:
如果您愿意假设主分支称为“master”,并且您从 master 创建其他分支,那么您可以将此别名添加到您的~/.gitconfig
文件中以使其变得简单:
cbranch = !"git branch | grep '*' | cut -f2 -d' '"
changed = !"git diff --name-only $(git cbranch) $(git merge-base $(git cbranch) master)"
Those assumptions will work for most people in most situations, but you must be aware that you're making them.
在大多数情况下,这些假设对大多数人都适用,但您必须意识到您正在做出这些假设。
Also, you must use a shell that supports $()
. It's very likely that your shell supports this.
此外,您必须使用支持$()
. 您的 shell 很可能支持 this。
回答by Badari
git show --stat origin/branch_name
This will give you a list of the files that have been added or modified under this branch.
这将为您提供在此分支下添加或修改的文件的列表。
回答by The Godfather
For some reason no one mentioned git-tree
. See https://stackoverflow.com/a/424142/1657819
出于某种原因没有人提到git-tree
。见https://stackoverflow.com/a/424142/1657819
git-tree
is preferred because it's a plumbingcommand; meant to be programmatic (and, presumably, faster)
git-tree
首选,因为它是一个管道命令;意味着程序化(并且可能更快)
(assuming base branch is master
)
(假设基本分支是master
)
git diff-tree --no-commit-id --name-only -r master..branch-name
However this will show you allfiles which were affected in the branch, if you want to see explicitly modifiedfiles only, you can use --diff-filter
:
但是,这将显示分支中受影响的所有文件,如果您只想查看显式修改的文件,则可以使用--diff-filter
:
git diff-tree --no-commit-id --name-only -r master..branch-name --diff-filter=M
Also one can use --name-status
instead of --name-only
to see the status of the files (A
/M
/D
and so on)
也可以使用--name-status
,而不是--name-only
看文件的状态(A
/ M
/D
等)