git 区分当前文件版本和前一个远程存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10627389/
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
Diff current file version and previous one remote repository
提问by OscarRyz
How do I diff my working file version vs. some previous version in the remote repository?
如何将我的工作文件版本与远程存储库中的某个先前版本进行比较?
Say, I pull today, perform 6 - 8 commits to my local copy and then want to see the diff between my latest working version ( of a given file ) and the latest on the remote or any other version.
比如说,我今天拉取,对我的本地副本执行 6 - 8 次提交,然后想查看我的最新工作版本(给定文件的)与远程或任何其他版本上的最新版本之间的差异。
采纳答案by meagar
If you're talking about a remote branch, say, origin/master
, you can use ~
and ^
to refer to ancestor commits relative to a branch the same way you can with local branches:
如果您在谈论远程分支,例如,origin/master
您可以使用~
和^
来引用相对于分支的祖先提交,就像使用本地分支一样:
# what change was introduced to origin/master in the last 4 commits?
git diff origin/master origin/master~3
If you want to diff your current working directory against the 5th most recent commit on origin/master
, you would omit the first argument:
如果要将当前工作目录与 5th 最近的提交进行比较origin/master
,则可以省略第一个参数:
git diff origin/master~4
回答by GoZoner
To see the diff between your 'latest working version' (I'll take that as your working copy) use:
要查看您的“最新工作版本”(我将其作为您的工作副本)之间的差异,请使用:
git diff <remote>/<branch>
If you think somebody else has pushed to the remote then you need to fetch the changes:
如果您认为其他人已推送到远程,那么您需要获取更改:
git fetch <remote> <branch>
git diff <remote>/<branch>
If you want to restrict the diff to just a file or to all files in a directory use:
如果要将差异限制为仅一个文件或目录中的所有文件,请使用:
git diff <remote>/<branch> -- /path/to/file
git diff <remote>/<branch> -- /path/to/ #all files in directory
You can use git difftool ...
to start a visual diff tool (assuming one exists on your machine).
您可以使用git difftool ...
来启动可视化差异工具(假设您的机器上存在)。
回答by dinosaur
Suppose path/to/file.txt
is some file that's committed to the remote branch origin/master
and is also in my workspace, committed to the local branch my-branch
.
假设path/to/file.txt
有一些文件提交到远程分支origin/master
并且也在我的工作区中,提交到本地分支my-branch
。
Difference between the latest version of path/to/file.txt
committed the remote branch and the (possibly uncommitted) version in my workspace:
已path/to/file.txt
提交远程分支的最新版本与我工作区中(可能未提交的)版本之间的差异:
git diff origin/master:path/to/file.txt path/to/file.txt
Difference between the version of path/to/file.txt
committed the remote branch three commits ago and the (possibly uncommitted) version in my workspace:
path/to/file.txt
三次提交前提交的远程分支的版本与我工作区中的(可能未提交的)版本之间的差异:
git diff origin/master~3:path/to/file.txt path/to/file.txt
Difference between the latest version of path/to/file.txt
committed the remote branch and the latest version committed to my-branch
:
path/to/file.txt
提交远程分支的最新版本与提交到的最新版本之间的区别my-branch
:
git diff origin/master:path/to/file.txt my-branch:path/to/file.txt
回答by Amos Folarin
git fetch; #this will attach the remote branch commits to your local tree git diff FETCH_HEAD #diff your working dir version of my_file vs the remote tip same as git diff remotes/origin/branch
But you must do a git-fetch first or you won't have the remote's commits locally available to diff against
但是您必须先执行 git-fetch 否则您将无法在本地使用远程提交来进行比较