创建一个没有父节点的分支
2015-08-06 13:19
393 查看
http://stackoverflow.com/questions/5689960/how-do-i-create-a-commit-without-a-parent-in-git 这个问题和第二个链接是重复的问题
http://stackoverflow.com/questions/645450/insert-a-commit-before-the-root-commit-in-git
Here’s a cleaner implementation of the same solution, in that it works without the need to create an extra repository, futz around with remotes, and correct a detached head:
# first you need a new empty branch; let's call it `newroot`
git checkout --orphan newroot
git rm -rf .
# then you apply the same steps
git commit --allow-empty -m 'root commit'
git rebase --onto newroot --root master
git branch -d newroot
Voila, you’ve ended up on master with its history rewritten to include an empty root commit.
NB.: on old versions of Git that lack the --orphan switch to checkout, you need the plumbing to create an empty branch:
git symbolic-ref HEAD refs/heads/newroot
git rm --cached -r .
git clean -f -d
git官方文档关于git checkout
--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.
The index and the working tree are adjusted as if you had previously run "git checkout <start_point>". This allows you to start a new history that records a set of paths similar to <start_point> by easily running "git commit -a" to make the root commit.
This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.
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. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.
http://stackoverflow.com/questions/645450/insert-a-commit-before-the-root-commit-in-git
Here’s a cleaner implementation of the same solution, in that it works without the need to create an extra repository, futz around with remotes, and correct a detached head:
# first you need a new empty branch; let's call it `newroot`
git checkout --orphan newroot
git rm -rf .
# then you apply the same steps
git commit --allow-empty -m 'root commit'
git rebase --onto newroot --root master
git branch -d newroot
Voila, you’ve ended up on master with its history rewritten to include an empty root commit.
NB.: on old versions of Git that lack the --orphan switch to checkout, you need the plumbing to create an empty branch:
git symbolic-ref HEAD refs/heads/newroot
git rm --cached -r .
git clean -f -d
git官方文档关于git checkout
--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.
The index and the working tree are adjusted as if you had previously run "git checkout <start_point>". This allows you to start a new history that records a set of paths similar to <start_point> by easily running "git commit -a" to make the root commit.
This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.
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. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.
相关文章推荐
- [Usaco2008 Open]Word Power 名字的能量
- Ubuntu下crontab命令的用法
- Tabbar与Navigation嵌套
- MVC dropdownlist自动绑定、验证、默认值
- 人证比对TCPSERVER
- LeetCode手记-Add Binary
- 整理 Anglarjs的service,directve的基本用法
- 单元测试覆盖率生成网页报告----(五)邮件通知
- 使用CSS3画出一个叮当猫
- 支付宝条码支付
- MongoVUE怎样插入数据
- Divide Groups
- java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
- VIM 配置
- AngularJS下的后台传值问题
- mysql 错误 SQL Er…
- 如何在MySql中设置外键约束
- Visual Studio 2010旗舰…
- 浅谈MFC中BitBlt与StretchDIBits的区别
- Extjs textfield 宽