Git:两​​个初始提交

标签 git branch

我有一个最近开始使用版本控制的项目。
在这个项目中有一个使用完全不同代码的旧尝试,我想将其添加到后代的版本控制中,但它既不是当前 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/

相关文章:

git - 获取漂亮的 git rev 名称

git - 我什么时候应该创建一个新分支?

git - Git 中的行结尾搞砸了 - 如何在巨大的行结尾修复后跟踪另一个分支的更改?

git push 失败,拒绝更新 stash 引用

分支开关上的 GIT 污迹过滤器 : How to get log from "new" branch?

java - INTELLIJ IDEA 错误 : "Can' t start Git:/usr/bin/git Probably the path to Git executable is not valid. 修复它。”如何修复?

git - 如何将现有的非空目录转换为位于另一个目录中的现有非空 git repo 的 git 分支

svn - 使用奇数分支结构时 Git-svn 分支软管 dcommit

git - Git重命名匹配可以忽略空格更改吗?

git - Ansible git clone 'Permission Denied' 但直接 git clone 工作