听起来像你想要做的是从master
和this answer创建新的develop
分支的组合,用于How to insert a commit as the first, shifting all the others?。
比方说,你有一个像历史上的以下内容:
$ git --version
git version 1.7.9.rc2.1.g69204
$ git log --oneline --decorate --all
3047e68 (HEAD, master) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
创建一个从master
分支新develop
分支:
$ git branch develop
$ git log --oneline --decorate --all
3047e68 (HEAD, master, develop) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
创建一个新的初始提交并进行设置,你怎么样:
$ git symbolic-ref HEAD refs/heads/newroot
$ git rm --cached -r .
$ git add README.md
$ git clean -f -d
$ git commit -m 'new initial'
$ git log --oneline --decorate --all
8b9881c (HEAD, newroot) new initial
3047e68 (master, develop) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
现在制作newroot
的develop
分支和新的初始提交master
分支:
$ git rebase --onto newroot newroot develop
$ git branch -d newroot
$ git log --oneline --decorate --all
3d589b6 (HEAD, develop) D
f6a83da C
6c8bdc9 B
f8dd99f A
79706b0 initial
8b9881c new initial
3047e68 (master) D
d5b5fdb C
4a26775 B
c53013b A
2a984b8 initial
现在,你以后一定要摆脱现有master
历史,使new initial
提交master
的HEAD
:
$ git reset --hard 8b9881c
HEAD is now at 8b9881c new initial
$ git log --oneline --decorate --all
3d589b6 (develop) D
f6a83da C
6c8bdc9 B
f8dd99f A
79706b0 initial
8b9881c (HEAD, master) new initial
而当develop
分支是稳定的,并准备master
:
$ git checkout master
$ git merge --no-ff develop
$ git log --oneline --graph --decorate --all
* e8a5c32 (HEAD, master) Merge branch 'develop'
|\
| * 3d589b6 (develop) D
| * f6a83da C
| * 6c8bdc9 B
| * f8dd99f A
| * 79706b0 initial
|/
* 8b9881c new initial
这没有任何意义。你能否解释一下你试图完成的任务是将你的'master'分支清空?这与使其稳定无关,只是使它变得空虚无用。我也很困惑你的意思是“长期运行”的分支。主人应该是*最长的*运行分支。按照惯例,它应该是整个项目历史中始终存在的唯一分支。 – meagar 2012-04-04 12:01:10
@meagar我想我解释了我的后面:*主人不应该是一个长期运行的分支。作为其他人,我认为主分支总是持有稳定的产品。*。通过*长期运行*,我的意思是开发分支。 – tugberk 2012-04-04 12:06:52
* master *分支可以并且应该保持稳定的产品,但这意味着(正如我所说)它应该是最长的运行分支*。它应该始终存在,而您的开发和功能分支合并并分叉并消失。 – meagar 2012-04-04 12:08:43