git checkout 分支但保留在 master 中

标签 git

我通常使用这个命令切换分支

git fetch && git checkout branch

之后,我通常会通过 git info 来检查我是否在我想要的分支上工作,这会突出显示我正在工作的本地分支(在分支名称)。

我今天遵循相同的模式,但不知何故 git 仍然在 ma​​ster 分支中,即使在我运行 git fetch && git checkout branch 之后也是如此。命令行中没有错误日志。但是在那之后,git info 显示了这样的东西(本地分支仍然是 ma​​ster,而不是我想切换到的分支 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.

在我手动解决ma​​ster 上的冲突后,现在git fetch && git checkout threads工作正常,我可以切换到分支线程

至于为什么我一开始就得到了一个diverged master,我不确定 - 也许是一些git rebase的结果我没有正确执行命令。

关于git checkout 分支但保留在 master 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31245941/

相关文章:

git urlencode 一些字符

python - Python 项目的预提交 Hook

git - 我可以强制 git diff 将文件视为副本吗?

git - 列出计划的 curl 请求中的身份验证失败

git 切换分支而不丢弃本地更改

git - Visual Studio 2015 默认为 P4VS,即使解决方案由 git 控制

java - 收到致命警报 : bad_record_mac when Git Push with netbeans 8

git - Heroku Git - fatal error : The remote end hung up unexpectedly

git - 忽略 Visual Studio Code git diff View 中的空格

git - ssh:无法解析主机名(Docker、gitlab-ce)