以下一系列git命令导致存储库有所不同。我究竟做错了什么?
称父项目为“上游”
git pull --rebase上游主服务器
git push origin master
git pull
最终使历史混乱的事情。什么是正确的方法?
让我们解决这个问题。
有3个存储库:您的本地克隆,上游,您的fork(起源于您的本地克隆)
步骤2之后,它们看起来像这样:
上游的
o---o---o
a b c
叉子
o---o---o
a b c
本地
o---o---o
a b c
在第5步之后,存储库如下所示:
上游的
o---o---o---o---o
a b c d e
叉子
o---o---o---o---o---o
a b c f g h
本地
o---o---o---o---o---o
a b c f g h
也就是说,上游有新的提交d
和e
,你已经取得了新的提交f
,g
并h
你现在做 git pull --rebase upstream master
现在,存储库如下所示:
上游的
o---o---o---o---o
a b c d e
叉子
o---o---o---o---o---o
a b c f g h
本地
o---o---o---o---o---o---o---o
a b c d e f' g' h'
其中f
和f'
不相同的提交-f'
应该等效于f
,但是其父级不同。
你可以在这里看到,那个地方有不同的历史,现在到叉; 推动它不仅仅是添加新提交的情况。两者都认为在之后有一个不同的提交c
,并且两个分支不收敛。如果添加了所有提交,最终将得到以下图形:
,-----------o---o---o
| f g h
o---o---o---o---o---o---o---o
a b c d e f' g' h'
而当前的HEAD是什么?h
还是h'
?两者都不保留对方的历史。
你可以合并这些,而是因为你有相当的变化,这将是错误的f
和f'
,g
和g'
等。
你可以做
git push -f
这将丢弃f
,g
并将其h
从fork移开,使其看起来像local(您将拥有f'
,g'
并且h'
仍然),如果没有其他人从fork克隆,则可能很好
在第6步中,您可以做的不是重设基础
git pull upstream master
这将导致合并,因此存储库如下所示:
上游的
o---o---o---o---o
a b c d e
叉子
o---o---o---o---o---o
a b c f g h
本地
,---o---o---o---,
| f g h |
o---o---o---o---o-------o
a b c d e m
m
合并提交在哪里。然后,这可能会被轻而易举地分叉,因为它只是添加了额外的提交。
但是,如果您打算向上游发出拉取请求,则最好不要合并其更改,并让他们拉并处理合并。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句