我通常使用这个命令切换分支
git fetch && git checkout branch
之后,我通常会通过 git info
来检查我是否在我想要的分支上工作,这会突出显示我正在工作的本地分支(在分支名称)。
我今天遵循相同的模式,但不知何故 git 仍然在 master 分支中,即使在我运行 git fetch && git checkout branch
之后也是如此。命令行中没有错误日志。但是在那之后,git info
显示了这样的东西(本地分支仍然是 master,而不是我想切换到的分支 threads)。
## Remote Branches:
origin/HEAD -> origin/master
origin/master
origin/threads
## Local Branches:
* master
与正常情况相比(当 git checkout branch
按预期工作时)——奇怪的是似乎有两个 origin/master
,第一个 origin/HEAD -> origin/master
看起来很正常;我不确定第二个。
这里有一些奇怪的东西,但我还没弄清楚。
最佳答案
看来我得到了一个发散的 master。
奇怪的是,这个命令没有显示任何错误日志。
$ git fetch && git checkout threads # threads is the name of the branch
但是,
$ git fetch && git checkout master
Switched to branch 'master'
Your branch and 'origin/master' have diverged,
and have 7 and 3 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
和,
$ git pull origin master
From <git_repo> # <git_repo> is the URL of the repo
* branch master -> FETCH_HEAD
Auto-merging <file> # <file> is the filename in question
CONFLICT (add/add): Merge conflict in <file>
Automatic merge failed; fix conflicts and then commit the result.
在我手动解决master 上的冲突后,现在git fetch && git checkout threads
工作正常,我可以切换到分支线程。
至于为什么我一开始就得到了一个diverged master,我不确定 - 也许是一些git rebase
的结果我没有正确执行命令。
关于git checkout 分支但保留在 master 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31245941/