Git中我仍然感到困惑的一种情况是:
$ git clone https://github.com/dude1/project
糟糕,那不是正确的版本。我会切换到另一个版本:
$ git remote add dude2 https://github.com/dude2/project
$ git fetch dude2
$ git checkout dude2/master
Note: checking out 'dude2/master'.
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 f3o845a...
嗯,我希望 master
指的是dude2/master。
$ git checkout -b master dude2/master
fatal: A branch named 'master' already exists.
除了删除整个目录并重新开始,我应该如何干净地切换存储库?
-B
而不是-b
。 - jthillclone
时复制了第一个远程仓库的内容。当你将主分支切换到第二个远程仓库时,差异被视为你自己创建的提交,从而"分叉"了主分支和远程仓库的关系。 - Klas Mellbourn