2

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.

没有删除整个目录并重新开始,我如何干净地切换存储库?

4

2 回答 2

3

在 git 中,您不应该在远程分支上提交工作(您应该在本地分支上完成工作),这就是为什么您'detached head' statecheckout dude2/master. 远程分支应该包含来自远程的提交副本,而不是本地创建的提交。

正如 jthill 所建议的,强制转换方式的最佳方法master

git checkout -B master dude2/master

输出应包括

Branch master set up to track remote branch master from dude2.

表示您的 master 现在正在跟踪不同远程 master 的更改。

于 2013-06-12T17:01:31.410 回答
0

考虑到这一点,显而易见的答案是:

首先git checkout dude2/master如上。然后:

$ git branch -d master
warning: deleting branch 'master' that has been merged to
     'refs/remotes/dude1/master', but not yet merged to HEAD.
Deleted branch master (was f30845a).

$ git checkout -b master dude2/master
Branch master set up to track remote branch master from dude2.
Switched to a new branch 'dude2'

我不知道删除主人时的警告是什么意思。

于 2013-06-12T08:52:44.490 回答