git 显示哪些文件在两个修订版之间发生了变化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/822811/
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
Showing which files have changed between two revisions
提问by johannix
I want to merge two branches that have been separated for a while and wanted to know which files have been modified.
我想合并两个分开一段时间的分支,想知道修改了哪些文件。
Came across this link: http://linux.yyz.us/git-howto.htmlwhich was quite useful.
发现这个链接:http: //linux.yyz.us/git-howto.html,这非常有用。
The tools to compare branches I've come across are:
我遇到的比较分支的工具是:
git diff master..branch
git log master..branch
git shortlog master..branch
git diff master..branch
git log master..branch
git shortlog master..branch
Was wondering if there's something like "git status master..branch" to only see those files that are different between the two branches.
想知道是否有类似“git status master..branch”之类的东西来只查看两个分支之间不同的文件。
Without creating a new tool, I think this is the closest you can get to do that now (which of course will show repeats if a file was modified more than once):
无需创建新工具,我认为这是您现在最接近的方法(如果文件被多次修改,当然会显示重复):
git diff master..branch | grep "^diff"
git diff master..branch | grep "^diff"
Was wondering if there's something I missed...
想知道是否有什么我错过了......
回答by JasonSmith
To compare the current branch against master
branch:
将当前分支与master
分支进行比较:
$ git diff --name-status master
To compare any two branches:
比较任意两个分支:
$ git diff --name-status firstbranch..yourBranchName
Read up on git diff
in the official documentation.
阅读上git diff
的的正式文件。
回答by Gerry
Try
尝试
$ git diff --stat --color master..branchName
This will give you more info about each change, while still using the same number of lines.
这将为您提供有关每个更改的更多信息,同时仍然使用相同数量的行。
You can also flip the branches to get an even clearer picture of the difference if you were to merge the other way:
如果您要以另一种方式合并,您还可以翻转分支以更清楚地了解差异:
$ git diff --stat --color branchName..master
回答by Eric Anderson
Also keep in mind that git has cheap and easy branching. If I think a merge could be problematic I create a branch for the merge. So if master
has the changes I want to merge in and ba
is my branch that needs the code from master I might do the following:
还请记住,git 具有廉价且易于分支的功能。如果我认为合并可能有问题,我会为合并创建一个分支。因此,如果master
有我想要合并的更改,并且ba
我的分支需要来自 master 的代码,我可能会执行以下操作:
git checkout ba
git checkout -b ba-merge
git merge master
.... review new code and fix conflicts....
git commit
git checkout ba
git merge ba-merge
git branch -d ba-merge
git merge master
End result is that I got to try out the merge on a throw-away branch before screwing with my branch. If I get my self tangled up I can just delete the ba-merge
branch and start over.
最终结果是我必须在与我的分支拧紧之前在一次性分支上尝试合并。如果我把自己弄乱了,我可以删除ba-merge
分支并重新开始。
回答by Paulino III
If anyone is trying to generate a diff file from two branches :
如果有人试图从两个分支生成差异文件:
git diff master..otherbranch > myDiffFile.diff
回答by Yantao Xie
There is also a GUI based method.
还有一种基于 GUI 的方法。
You can use gitk.
您可以使用gitk。
Run:
$ gitk --all
Right click on a commit of a branch and select Mark this commitin the pop-up menu.
- Right click on a commit of another branch and select Diff this -> marked commitor Diff marked commit -> this.
跑:
$ gitk --all
右键单击某个分支的提交,然后在弹出菜单中选择“标记此提交”。
- 右键单击另一个分支的提交并选择Diff this -> 标记提交或Diff 标记提交 -> this。
Then there will be a changed files list in the right bottom panel and diff details in the left bottom panel.
然后将在右下面板中显示更改的文件列表,在左下面板中显示差异详细信息。
回答by rsilva4
One more option, using meld in this case:
还有一种选择,在这种情况下使用 meld:
git difftool -d master otherbranch
This allows not only to see the differences between files, but also provides a easy way to point and click into a specific file.
这不仅允许查看文件之间的差异,而且还提供了一种指向并单击特定文件的简单方法。
回答by David Plumpton
Note that git makes it easy to just try out the merge and back away from any problems if you don't like the result. It might be easier than looking for potential problems in advance.
请注意,如果您不喜欢结果,git 可以轻松地尝试合并并避免任何问题。这可能比提前寻找潜在问题更容易。
回答by Mannu
And if you are looking for changes only among certain file(s), then:
如果您只在某些文件中查找更改,则:
git diff branch1 branch2 -- myfile1.js myfile2.js
branch1 is optional and your current branch (the branch you are on) will be considered by default if branch1 is not provided. e.g:
branch1 是可选的,如果未提供 branch1,则默认情况下会考虑您当前的分支(您所在的分支)。例如:
git diff master -- controller/index.js
回答by Alex Brown
When working collaboratively, or on multiple features at once, it's common that the upstream or even your master contains work that is not included in your branch, and will incorrectly appear in basic diffs.
当协同工作或同时处理多个功能时,上游甚至你的主包含不包含在你的分支中的工作是很常见的,并且会错误地出现在基本差异中。
If your Upstream may have moved, you should do this:
如果您的上游可能已经移动,您应该这样做:
git fetch
git diff origin/master...
Just using git diff master can include, or fail to include, relevant changes.
仅使用 git diff master 可以包含或不包含相关更改。
回答by Wim Deblauwe
If you are using IntelliJ IDEA, you can also compare any branch with your current working branch. See http://www.jetbrains.com/idea/webhelp/merging-deleting-and-comparing-branches.html#d288093e3827for more info. This is available in the free editionas well.
如果您使用的是IntelliJ IDEA,您还可以将任何分支与您当前的工作分支进行比较。有关更多信息,请参阅http://www.jetbrains.com/idea/webhelp/merging-deleting-and-comparing-branches.html#d288093e3827。这也可以在免费版中使用。