工作中有个项目需要个单独非分支放文档,该分支不继承任何提交,没有父节点,完全是一个干净的分支,使用git checkout命令创建的分支是有父节点的,包含了历史提交的,网站找了一下,所有就记录下来备用。

创建分支

使用git checkout--orphan参数:

git checkout --orphan document

该命令会创建一个名为doc的分支,并且该分支下有前一个分支下的所有文件。 查看--orphan的帮助:

Create a new orphan branch, named , started from and switch to it. The first commit made on the new branch will have no parents and it will be the root of a new history totally disconnected from all the other branchs and commits.

这里的start point指的是你执行git checkout命令时的那个分支,当然新的分支不会指向任何以前的提交,就是它没有历史,如果你提交当前内容,那么这次提交就是这个分支的首次提交。

清空内容

如果把当前内容全部删除,用git命令:

git rm -rf .

提交分支

此时,就可以在新的分支上写文档啦,然后使用git commit提交新的内容:

git commit -am "new branch for document"

查看新分支

使用branch来查看分支是否创建成功

git branch -a