git分支unkown但结帐工作 [英] git branch unkown but checkout works
问题描述
git remote update
和 git pull
。根据我的理解 git remote update
会更新所有设置为跟踪远程分支的分支,如下所述:git remote update,'git fetch'和'git pull'有什么区别? ?
所以当我输入 git diff master newBranch --name-only
我期望看到两个分支中不同的文件列表。但是,我收到了以下错误消息:
fatal:歧义参数'newBranch':未知版本或路径不在
如果我输入git checkout newBranch
它可以正常工作,如果我通过键入git checkout master
突然git diff master newBranch --name-only
切换回主目录?
任何人都可以向我解释这种行为吗?
解决方案你提到你没有分支的本地副本newBranch,所以你需要指定你想用远程的分支标签做这样的差异:
git diff origin / master origin / newBranch --name-only
或者假设你有本地主人:
git diff主起源/ newBranch --name-only
检查哪个分支你有本地的:
git branch -l
或
git分支
检查远程分支
git branch -r
检查所有分行:
git branch -a
因此,您在结帐后为您工作,因为git自动创建了一个名为newBranch的本地分支。所以在你的结帐之前
git branch
不会显示一个名为newBranch的分支,但是在结帐之后它会。on my remote repository a new branch has been created. In GitBash in my Working Directory (on master branch) I type
git remote update
andgit pull
. To my understandinggit remote update
will update all branches set to track remote ones as explained here: What is the difference between 'git remote update', 'git fetch' and 'git pull'?So when I type
git diff master newBranch --name-only
I expected to see a list of files which are different in both branches. But instead I got the following error message:fatal: ambiguous argument 'newBranch': unknown revision or path not in the working tree.
But if I type
git checkout newBranch
it works fine, and if I switch back to master by typinggit checkout master
suddenlygit diff master newBranch --name-only
works perfectly?Could anyone explain to me this behavior?
解决方案As you mentioned you don't have the local copy of the branch "newBranch" so you need to specify that you want to do a diff with the branch tag from the remote like this:
git diff origin/master origin/newBranch --name-only
or assuming you have the master locally:
git diff master origin/newBranch --name-only
Check which branches you have locally:
git branch -l
or
git branch
check remote branches
git branch -r
check all branches:
git branch -a
So this worked for you after you did a checkout because git automatically created a local branch called newBranch. So before your checkout
git branch
would not show a branch called "newBranch" but after the checkout it would.这篇关于git分支unkown但结帐工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!