问题描述
我想创建一个分支出主,但我需要这个分支有一个空树。经过一番研究后,我提出了以下情况:
- 主分支有一个虚拟文件提交。
- 我检出一个新分支
- 我删除所有文件并提交
- --allow-empty
以下命令可以帮助您:
$ git init
$ touch dummy
$ git add。
$ git commit -m'initial commit'
$ git checkout -b新分支
$ git rm -rf。
$ git commit -m'清理树'
$ git commit --allow-empty -m'新分支初始提交'
现在我想摆脱'清理树'提交。我正在尝试使用rebase - 像
$ git rebase --onto HEAD〜2 HEAD ^
但是我最终得到了一个单独的提交('initial commit')和所有引用(HEAD,master,new -科)。如果我检查到新分支,虚拟文件又回来了。
我的'新分支初始提交'去了哪里?我错过了什么?
Obs .:我这样做是因为我想要关联这些分支,但我不想保留来自父项的文件
true | git mktree | xargs git commit-tree -p master | xargs git分支新分支
这是最简单的一行
emptytree = $(git mktree< / dev / null)
emptycommit = $(git commit-tree -p master $ emptytree< dev / null)
git分支新分支$ emptycommit
I want to create a branch out of master but I need this branch to have an empty tree. After a bit of researching I've come up with the following situation:
- Master branch have a single commit with a dummy file.
- I checkout a new branch
- I remove all files and commit
- I create a new commit with --allow-empty
The following commands should get you up to that:
$ 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'
Now I want to get rid of 'clean up tree' commit. I'm trying to use rebase --onto like
$ git rebase --onto HEAD~2 HEAD^
But I end up with a single commit ('initial commit') and all refs on it (HEAD, master, new-branch). And if I checkout into new-branch, dummy file is back.
Where did my 'new branch initial commit' went? What I'm a missing?
Obs.: I'm doing this because I want to relate those branches but I don't want to keep the files from the parent commit.
true | git mktree | xargs git commit-tree -p master | xargs git branch new-branch
which is the quickest one-liner for
emptytree=$(git mktree </dev/null)
emptycommit=$(git commit-tree -p master $emptytree </dev/null)
git branch new-branch $emptycommit
这篇关于git rebase - 在单次提交时结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!