gpt4 book ai didi

Git checkout 区别 git checkout origin/ 和 git checkout

转载 作者:行者123 更新时间:2023-12-04 12:17:51 33 4
gpt4 key购买 nike

当我这样做时 git checkout origin/bugfix/NTP-183-datefns git 显示

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/<branch-name>是远程分支引用。它不能被修改。
因此,当您 checkout 此引用时,git 无法将您移至此分支,但会将您移至该分支引用的提交。然后您在 分离头 状态,这意味着您不在分支上,而是直接在提交上(在命令的输出中解释了含义)。
<branch-name>只是一个本地分支,因此您可以对其进行处理。
因此,当您 checkout 此引用资料时,git 会将您移至该分支。

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

关于Git checkout 区别 git checkout origin/<branch-name> 和 git checkout <branch-name>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45813147/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com