我有一个最近开始使用版本控制的项目。
在这个项目中有一个使用完全不同代码的旧尝试,我想将其添加到后代的版本控制中,但它既不是当前 master
分支初始提交的祖先也不是后代。
我希望为此创建一个新的并行分支,没有以前的历史记录(即有多个“初始提交”)。Git 可以不用创建第二个存储库吗?提交树看起来像这样:
o---o---o master
\
o---o branch
o old implementation
这样我就可以简单地使用 git checkout old
来访问代码。它不得在 90 天后被垃圾收集器清理,并且可以选择标记。
最佳答案
git checkout
对于这种用例有一个选项:--orphan
.
来自 Git 手册:
--orphan <new_branch>
Create a new orphan branch, named
<new_branch>
, started from<start_point>
and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.
此外,该男子明确表示:
If you want to start a disconnected history that records a set of paths that is totally different from the one of
<start_point>
, then you should clear the index and the working tree right after creating the orphan branch by running "git rm -rf .
" from the top level of the working tree.
关于Git:两个初始提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18743715/