如何区分本地分支和远程分支?
当前回答
我就是这么做的。
# 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 diff remotes/origin/development..development
Or
git fetch origin
git diff origin/development
我一直看到这个错误
git diff main origin/master
fatal: ambiguous argument 'main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
解决方案:我必须先推git(因为远程和本地都需要是最新的),然后这样工作:
git diff master origin/master
如果你想看到的区别只是文件名的改变,那么使用:
git diff --name-status <remote-branch> <local-branch>
否则,这将显示两个分支之间的所有差异:
git diff <remote-branch> <local-branch>
在我的情况下,我有一个名为heroku的第二个远程,这不是起源,因为它不同步,我在试图运行git diff master heroku/master时得到了这个错误:
致命:模糊的参数“heroku/master”:未知的修订或路径不在工作树中。
或者当尝试其他方法git diff master. heroku/master:
致命:糟糕的修订'master..heroku/master'
解决方案是在运行git diff之前显式地在git fetch中提到远程名称,在我的情况下:
$ git fetch heroku
$ git diff master heroku/master
第一个类型
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告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是