如何在 2 个不同的本地分支之间的同一个文件上调用 git diff?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38664421/
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
How do I call git diff on the same file between 2 different local branches?
提问by akantoword
Is there a way to check the difference between the working directory in my current branch against the working directory of another branch in a specific file? For example, if I'm working in branch A on file 1, I want to compare the difference with file 1 on branch B.
有没有办法检查我当前分支中的工作目录与特定文件中另一个分支的工作目录之间的差异?例如,如果我在文件 1 上的分支 A 中工作,我想比较分支 B 上与文件 1 的差异。
回答by Patrick Murphy
Use the git diff branch branch filename syntax:
使用 git diff 分支分支文件名语法:
git diff branchA branchB -- file.cs
put the two names of your branches and optionally use the -- filename
option to specify one file! Good luck, let me know if you have issues.
输入分支的两个名称,并可选择使用-- filename
指定一个文件的选项!祝你好运,如果你有问题,请告诉我。
回答by arulraj.net
The following will help if you want to compare different files in two branches
如果您想比较两个分支中的不同文件,以下内容将有所帮助
git diff develop:foo.txt master:bar.txt
回答by Don Branson
Say you're on one branch, called legacy
, and want to compare the file build.gradle
to the same version on the master
branch:
假设您在一个名为 的分支上,legacy
并且想要将文件build.gradle
与master
分支上的相同版本进行比较:
git diff master build.gradle
git diff master build.gradle