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


当前回答

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

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

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

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

其他回答

我就是这么做的。

# 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 fetch,然后:

git diff <mainbranch_path> <remotebranch_path>

您可以git branch -a列出所有分支(本地和远程),然后从列表中选择分支名称(只需从远程分支名称中删除remotes/即可)。

例如:git diff main origin/main(其中“main”是本地主分支,“origin/main”是远程分支,即原点和主分支。)

例子

git diff 'master' 'testlocalBranch'

如果你使用WebStorm这样的编辑器,你可以右键点击一个文件,选择比较分支,然后输入/选择你的分支。

在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 remote/my_topic_branch my_topic_branch

其中my_topic_branch是您的主题分支。