如何区分本地分支和远程分支?
当前回答
我更理解输出:
Git diff <远程跟踪分支> <本地分支>
它告诉我,如果我推本地分支,什么将被删除,什么将被添加。当然,它是一样的,只是相反,但对我来说,它更可读,我更舒服地看着将要发生的事情。
其他回答
要更新远程跟踪分支,你需要先输入git fetch,然后:
git diff <mainbranch_path> <remotebranch_path>
您可以git branch -a列出所有分支(本地和远程),然后从列表中选择分支名称(只需从远程分支名称中删除remotes/即可)。
例如:git diff main origin/main(其中“main”是本地主分支,“origin/main”是远程分支,即原点和主分支。)
如果你想看到的区别只是文件名的改变,那么使用:
git diff --name-status <remote-branch> <local-branch>
否则,这将显示两个分支之间的所有差异:
git diff <remote-branch> <local-branch>
git difftool <commit> .
这将比较您想要的提交和您的本地文件。不要忘记最后的点(本地)。
例如,比较你的本地文件和一些提交:
git difftool 1db1ef2490733c1877ad0fb5e8536d2935566341 .
(并且你不需要git fetch,除非需要与new commit进行比较)
设置
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
TLDR: git diff <本地分支> <远程分支>
当在shell中使用Git时,我喜欢首先通过四处查看来确定自己的方向。
下面是一个显示所有分支的命令
$ git branch -a # (or git branch --all)
* my-branch
master
remotes/origin/some-branch
remotes/origin/HEAD -> origin/master
remotes/origin/my-branch
remotes/origin/some-other-branch
remotes/origin/master
这里有两个本地分支(my-branch和master)和四个远程分支(some-branch、some-other-branch、master和my-branch)。
此外,my-branch旁边的星号表示我目前在该分支中(您也可以通过使用命令git status来知道这一点,该命令将输出:On branch my-branch.)。
注意:Git Bash shell中的远程分支显示为红色,而本地分支显示为绿色。
如果你只想显示远程分支:
$ git branch -r # (or git branch --remotes)
origin/some-branch
origin/HEAD -> origin/master
origin/my-branch
origin/some-other-branch
origin/master
为了只显示本地分支,您可能会使用git branch -l,但这是一个完全不同的命令。要显示本地分支,请使用没有选项的git branch
$ git branch
* my-branch
master
为了完成对基本分支选项的回顾,有一个——列表,与您可能期望的相反,它允许过滤。使用它的模式如下:
$ git branch --list 'my*'
* my-branch
您还可以将——list与选项-a和-r结合使用,但请确保相应调整您的模式(记住:远程分支以“remotes”开头)。
例子:
# This will show all branches (local & remote) that start with my
$ git branch --list 'my*' -a
* my-branch
# Better: the pattern includes the remote
$ git branch --list '*my*' -a
* my-branch
remotes/origin/my-branch
文档:git分支
现在您可以比较所有可用分支中的任意两个分支(还可以比较两个局部分支或两个远程分支)。
这里我比较了本地的和远程的my-branch。它们是同步的,所以我没有得到任何输出:
$ git diff my-branch remotes/origin/my-branch
注意:您必须给出分支的全名,不带引号。
我还可以将本地my-分支与远程主服务器进行比较。这里我得到了一些输出,因为远程my-分支还没有合并到主分支中。
$ git diff my-branch remotes/origin/master
diff --git a/src/controllers/call.controller.js b/src/controllers/call.controller.js
index fd79b98..df3d798 100644
--- a/src/controllers/call.controller.js
+++ b/src/controllers/call.controller.js
@@ -261,7 +261,7 @@ function callController() {
/*
* Function: doCall
[ . . . ]
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别