简体   繁体   English

如何找出git分支中更改的文件(不是两个分支之间的差异)

[英]How to find out what files were changed in a git branch (not the difference between two branches)

I have a branch named feature_219 which was created from master a little while ago. 我有一个名为feature_219的分支,它是在不久前从master创建的。 Since the diversion, there were a number of files changed on both the branches. 自从转移以来,两个分支上都有许多文件发生了变化。

Now I am trying to figure out what files where changed while working on the feature_219 branch only. 现在我试图弄清楚在处理feature_219分支时哪些文件发生了变化。

After doing some research I found out that git diff --name-only master feature_219 might help but it turned out that this commands tells about all files that are different in both the branches. 在做了一些研究之后,我发现git diff --name-only master feature_219可能会有所帮助,但事实证明这个命令告诉了两个分支中不同的所有文件。 I tried to look for some option with this command but nothing worked for me. 我试图用这个命令寻找一些选项,但没有任何对我有用。

Is there any way to list only those files that were changed in feature_219 branch? 有没有办法只列出那些在feature_219分支中更改的文件?

According to the git diff documentation 根据git diff文档

git diff --name-only master...feature_219

should do the trick. 应该做的伎俩。 Notice the three dots. 注意三个点。 If you're currently on branch feature_219 如果您目前在分支feature_219

git diff --name-only master...

suffices. 就足够了。 The order of the two branches is very important. 两个分支的顺序非常重要。 Interchanging the two branches in the first call will give you all changes in the master branch since you started the feature_219 branch. 在第一次调用中交换两个分支将在您启动feature_219分支后master分支提供所有更改。

The command git diff A...B should be interpreted as "give me all changes which happen in the commits when going from A to B ". 命令git diff A...B应解释为“给我从AB的提交中发生的所有更改”。 If A is not a parent of B (as in this case) the common ancestor will be used to answer this question. 如果A不是B的父(在这种情况下),则共同的祖先将用于回答这个问题。

您可以使用git merge-base查找两个分支的共同祖先,然后获取差异。

git diff --name-only feature_219 $(git merge-base master feature_219)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM