git checkout差异git checkout origin/< branch-name>和git checkout< branch-name&gt ;? [英] Git checkout difference git checkout origin/<branch-name> and git checkout <branch-name>?

查看:86
本文介绍了git checkout差异git checkout origin/< branch-name>和git checkout< branch-name&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行 git checkout origin/bugfix/NTP-183-datefns git shows

When I do git checkout origin/bugfix/NTP-183-datefns git shows

Note: checking out 'origin/bugfix/NTP-183-datefns'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 6fd089d.

但是当我尝试 git checkout bugfix/NTP-183-datefns

Switched to branch 'bugfix/NTP-183-datefns'
Your branch is up-to-date with 'origin/bugfix/NTP-183-datefns'.

这是怎么回事?

推荐答案

origin/<分支名称> 是远程分支引用.无法修改.
因此,当您签出该引用时,git无法将您移至该分支,但会将您移至该分支引用的提交.然后,您处于分离的HEAD 状态,这意味着您不在分支上,而是直接在提交上(含义在命令输出中进行了解释).

origin/<branch-name> is a remote branch reference. It cannot be modified.
So when you checkout this reference, git cannot move you to this branch but it moves you to the commit referenced by the branch. You are then in a detached HEAD state, which means you're not on a branch but directly on a commit (implications are explained in the output of the command).

<分支名称> 只是一个本地分支,因此您可以对其进行处理.
因此,当您签出此引用时,git会将您移至分支.

<branch-name> is simply a local branch, so you can work on it.
So when you checkout this reference, git moves you to the branch.

有一点提示:如果本地分支< branch-name> 不存在,但在所有远程站点上仅存在一个同名远程分支,则git会自动创建本地分支跟踪远程分支并检出它(在这种情况下, git checkout< branch-name> 等效于 git checkout --track -b< branch-name> any_remote/< branch-name> )

There is a little hint: if the local branch <branch-name> doesn't exists but there exists exactly one remote branch with the same name over all the remotes, git will automatically create the local branch tracking the remote branch and checkout it (in this case git checkout <branch-name> is equivalent to git checkout --track -b <branch-name> any_remote/<branch-name>)

这篇关于git checkout差异git checkout origin/&lt; branch-name&gt;和git checkout&lt; branch-name&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆