Par*_*yes 6 git version-control git-rebase git-flow git-rewrite-history
我正在使用一个理论上应该遵循Gitflow工作流程的存储库(参见Vincent Driessen 成功的git分支模型).但是,存储库上的初始提交是在develop分支上进行的,并且没有master可见的分支.它即将发布时间,我需要创建一个master分支,反映项目的生产就绪状态,应该从一开始就存在.请记住,develop分支有多个功能分支.存储库完全是本地的,尚未推送.
我的想法是创建一个孤儿分支master并将develop分支重新分支到它上面,但我不知道我该如何去做.
那么,我怎样才能创建master分支,就像它从一开始就创建一样?
更新:在我的情况下,第一次提交develop不是应该被认为适合生产的提交,因此使用它作为初始master提交将是不明智的.项目处于此状态的原因是因为它在决定使用Git时最初没有使用VCS.
经过一番摆弄,这就是我想出的。这是VonC 答案的一种更简单的手动方法。
假设您有一个develop包含存储库初始提交的分支,并且您想重写历史记录,以便master分支包含新的初始提交。
首先,如果您的develop分支上的初始提交适合作为新master分支上的初始提交,那么您只需在master那里创建分支即可:
$ git branch master <sha1-of-initial-commit-on-develop>
Run Code Online (Sandbox Code Playgroud)
如果你没有那么奢侈,那么你需要创建一个新的空提交,作为master.
# Create the new master branch
$ git checkout --orphan master
# Clear the working directory (we want the initial commit to be empty)
$ git rm -rf .
# Create the initial commit on master
$ git commit --allow-empty -m "Initial commit"
# Rebase the entire develop branch onto the new master branch
$ git rebase --onto master --root develop
Run Code Online (Sandbox Code Playgroud)
如果有任何树枝从树枝上掉下来develop,它们就会“大乱”。这是因为那些分支(我们将称它们为主题分支)在旧develop分支被重新定位之前仍然指向旧分支。如果你没有从树枝上掉下来的develop树枝,那么你就完成了。
每个主题分支都必须重新定位到新develop分支上。为此,我们将按照另一个问题(Git: How to rebase to a specific commit?)中概述的步骤进行操作。对于每个主题分支,请执行以下步骤。
用<common-ancestor>新创建的develop分支上的提交的 sha1替换主题分支应该分支的分支。
$ git branch temp <common-ancestor>
$ git checkout <topic-branch>
$ git rebase temp
$ git branch -d temp
Run Code Online (Sandbox Code Playgroud)
就是这样!请记住,您不应该在与其他人合作的分支上进行变基。
| 归档时间: |
|
| 查看次数: |
3215 次 |
| 最近记录: |