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


当前回答

第一个类型

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 <local branch> <remote>/<remote branch>

例如,git diff main origin/main,或者git diff feat尿素origin/next

当然,说到远程跟踪分支,你首先需要git fetch;并且您需要它拥有关于远程存储库中分支的最新信息。

这很简单。你可以使用:git diff remote/my_topic_branch my_topic_branch

其中my_topic_branch是您的主题分支。

如果你想看到的区别只是文件名的改变,那么使用:

git diff --name-status <remote-branch> <local-branch>

否则,这将显示两个分支之间的所有差异:

git diff <remote-branch> <local-branch>
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>

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