git:文件在本地回购和原点之间的差异 [英] git: diff between file in local repo and origin

查看:107
本文介绍了git:文件在本地回购和原点之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到我在本地存储库中的文件与原始大师存在的文件之间的差异。



我知道有git diff,但是我只是想将它隔离到这个特定的文件。

为了简单起见,可以说文件名为file1.txt,它有一个本地文件path = [local_path]并在源文件中有filepath = [remote-path]。



我需要键入的git命令是什么?

编辑:谢谢大家的意见,它一直非常有见地。对于那些正在使用Eclipse的人(我和我应该早些说明),我只是发现你可以右键单击 - >比较 - >分支,标记或引用 - >选择合适的版本,然后你就可以开始了。 > [local-path] 是一样的,你可以这样做:

$ $ $ $ $ $ $ $ $ git fetch origin master
$ git diff origin / master - [local-path]

注1 :上面的第二个命令将与本地存储的远程跟踪分支进行比较。 fetch命令需要将远程跟踪分支更新为与远程服务器的内容同步。或者,您可以只做

  $ git diff master:<路径或文件名称> 

注2: master 可以在上面的例子中用任何分支名称替换


I want to find the differences between a file I have in my local repo vs what is in the origin master.

I know that there is git diff, however I just want to isolate it down to this one particular file.

For simplicity lets say the files is named file1.txt and it has a local file path = [local_path] and in the origin it has filepath = [remote-path].

What would be the git command I need to type?

EDIT: Thank you all for your input it has been very insightful. For those that are using Eclipse (which I am and I should have stated earlier) I just found out that you can just rightclick -> Compare With -> Branch, Tag or Reference -> select appropriate version and there you go.

解决方案

If [remote-path] and [local-path] are the same, you can do

$ git fetch origin master
$ git diff origin/master -- [local-path]

Note 1: The second command above will compare against the locally stored remote tracking branch. The fetch command is required to update the remote tracking branch to be in sync with the contents of the remote server. Alternatively, you can just do

$ git diff master:<path-or-file-name>

Note 2: master can be replaced in the above examples with any branch name

这篇关于git:文件在本地回购和原点之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆