git diff between remote and local repo

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

Trying to diff my local file with a GitHub repo before I submit a pull request so I can see what will show up, is there an accurate way of doing this? I assume GitHub's compare tool manipulates Git's diff?

回答1:

Don't do a pull :

  • do a fetch (the syntax is the same as git pull, but it doesn't automatically merge)
  • do a diff between your dest branch and the other branch
  • then do a merge if you want


回答2:

To compare a local working directory against a remote branch, for example origin/master:

  1. git fetch origin master
    This tells git to fetch the branch named 'master' from the remote named 'origin'. Git fetch will not affect the files in your working directory; it does not try to merge changes like git pull does.
  2. git diff --summary FETCH_HEAD
    When the remote branch is fetched, it can be referenced locally via FETCH_HEAD. The command above tells git to diff the working directory files against FETCHed branch's HEAD and report the results in summary format. Summary format gives an overview of the changes, usually a good way to start;
  3. git diff FETCH_HEAD -- mydir/myfile.js
    If you want to see changes to a specific file, for example myfile.js, skip the --summary option and reference the file you want (or tree).


回答3:

Per the OP's comment that part of his "problem was Windows vs. Unix LFs" this should help:

You can use the following config command to tell git-diff to ignore the difference of eol code.

git config --global core.whitespace cr-at-eol


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!