如何区分本地分支和远程分支?


当前回答

git difftool <commit> .

这将比较您想要的提交和您的本地文件。不要忘记最后的点(本地)。

例如,比较你的本地文件和一些提交:

git difftool 1db1ef2490733c1877ad0fb5e8536d2935566341 .

(并且你不需要git fetch,除非需要与new commit进行比较)

其他回答

我就是这么做的。

# To update your local.
git fetch --all

这将从远程获取所有内容,因此当您检查difference时,它将与远程分支进行比较。

# To list all branches
git branch -a

上面的命令将显示所有的分支。

# To go to the branch you want to check difference
git checkout <branch_name>
# To check on which branch you are in, use
git branch
    (or)
git status

现在,您可以检查如下差异。

git diff origin/<branch_name>

这将比较您的本地分支和远程分支。

第一个类型

git branch -a

获取可用分支的列表。在输出中,您可能会看到如下内容

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

然后显示差异

git diff --stat --color remotes/main/master..origin/master
git diff remotes/main/master..origin/master

我更理解输出:

Git diff <远程跟踪分支> <本地分支>

它告诉我,如果我推本地分支,什么将被删除,什么将被添加。当然,它是一样的,只是相反,但对我来说,它更可读,我更舒服地看着将要发生的事情。

设置

Git配置别名。Udiff 'diff @{u}'

带HEAD@{upstream}的差动HEAD

git fetch  # Do this if you want to compare with the network state of upstream; if the current local state is enough, you can skip this
git udiff

用任意远端分支差分

这回答了你标题中的问题(“它是远程的”);如果您希望区别于“远程”(未配置为分支的上游),则需要直接将其作为目标。您可以使用以下命令查看所有远程分支:

Git branch -r

您可以通过以下命令查看所有已配置的遥控器:

Git远程显示

你可以看到单个远程(例如origin)的分支/跟踪配置如下:

Git远程显示来源

一旦你确定了适当的起源分支,只需做一个正常的diff:)

git diff [MY_LOCAL] MY_REMOTE_BRANCH

让您的工作分支是开发分支,并且您希望区分本地开发分支和远程开发分支。在这种情况下,语法应该是这样的:

git diff remotes/origin/development..development

Or

git fetch origin
git diff origin/development