如何区分本地分支和远程分支?
当前回答
我就是这么做的。
# 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 --name-status <remote-branch> <local-branch>
否则,这将显示两个分支之间的所有差异:
git diff <remote-branch> <local-branch>
git difftool <commit> .
这将比较您想要的提交和您的本地文件。不要忘记最后的点(本地)。
例如,比较你的本地文件和一些提交:
git difftool 1db1ef2490733c1877ad0fb5e8536d2935566341 .
(并且你不需要git fetch,除非需要与new commit进行比较)
我一直看到这个错误
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拉的东西,这里有一个简单的答案。
git fetch
git diff FETCH_HEAD
第一个命令将找出与当前分支对应的远程分支。FETCH_HEAD引用中该计算的人工产物。然后,第二个命令使用该引用与当前分支的引用进行比较。
设置
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
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别