如何区分本地分支和远程分支?
当前回答
第一个类型
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>
这将比较您的本地分支和远程分支。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别