[英]git rebase --onto results on single commit
我想从master创建一个分支,但是我需要这个分支有一个空树。 经过一些研究后,我得出了以下情况:
以下命令可以帮助您:
$ git init
$ touch dummy
$ git add .
$ git commit -m 'initial commit'
$ git checkout -b new-branch
$ git rm -rf .
$ git commit -m 'clean up tree'
$ git commit --allow-empty -m 'new branch initial commit'
现在,我想摆脱“清理树”提交。 我正在尝试使用rebase --onto
$ git rebase --onto HEAD~2 HEAD^
但是我最后只有一个提交(“初始提交”)和所有引用(HEAD,master,new-branch)。 如果我结帐到新分支,虚拟文件又回来了。
我的“新分支初始提交”到哪里去了? 我缺少什么?
观察:我这样做是因为我想关联那些分支,但是我不想保留父提交中的文件。
true | git mktree | xargs git commit-tree -p master | xargs git branch new-branch
这是最快的单线
emptytree=$(git mktree </dev/null)
emptycommit=$(git commit-tree -p master $emptytree </dev/null)
git branch new-branch $emptycommit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.