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


当前回答

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

其中my_topic_branch是您的主题分支。

其他回答

在Visual Studio 2019中,只需要进行取回。不要拉代码。

这就是我所做的。我在.gitconfig文件中添加了以下内容,以便我可以使用Beyond Compare

File location: C:\Users\[username]\.gitconfig

添加以下

[diff]
    tool = bc
[difftool "bc"]
    path = c:/Program Files/Beyond Compare 4/bcomp.exe

打开命令提示符并进入工作目录。下面是本地开发分支和远程开发分支的比较:

git difftool dev origin/dev --dir-diff

这将打开Beyond Compare并打开包含不同文件的目录。如果没有任何变化,Beyond Compare将不会启动。

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

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

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

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

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

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

我就是这么做的。

# 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配置别名。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