compare local git branch with remote branch?

我如何看到本地分支和远程分支之间的diff


To update remote-tracking branches, you need to type git fetch first and then :

git diff <masterbranch_path> <remotebranch_path>

You can git branch -a to list all branches (local and remote) then choose branch name from list (just remove remotes/ from remote branch name.

Example: git diff master origin/master (where "master" is local master branch and "origin/master" is a remote namely origin and master branch.)


git diff <local branch> <remote>/<remote branch>

For example git diff master origin/master , or git diff featureA origin/next

Of course to have said remote-tracking branch you need to git fetch first; and you need it to have up to date information about branches in remote repository.


First type

git branch -a

to get the list of available branches. On the output you may see something like

* master
  remotes/main/master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/mt
  remotes/upstream/master
  remotes/upstream/mt

Then show the diff

git diff --stat --color remotes/main/master..origin/master
git diff remotes/main/master..origin/master
链接地址: http://www.djcxy.com/p/112.html

上一篇: 我如何将一个空目录添加到Git存储库?

下一篇: 比较本地git分支与远程分支?