将开发分支中所做的修改移动到新的 git-flow 功能分支中



我正在为我的项目使用 git-flow,并在开发分支中开始了一系列相当复杂的更改,这些更改似乎比我最初预期的要长。

我希望我在功能分支中完成此操作,因为我想通过其他更改制作新版本。如何将这些未提交的更改移动到新的 git-flow 功能分支中?

如果您没有提交

如果你只是一个肮脏的工作副本,就像你即将开始一个新功能一样:

git flow feature start awesomeness
git commit -va

如果您确实进行了一些提交

如果开发中的提交应该在您的功能分支中,则上述步骤是相同的。此外,尽管您会(可能 - 这不是必需的(希望将开发分支重置回开始为功能分支提交更改之前的位置,您可以使用:

git flow feature start awesomeness
git commit -va
git checkout develop
git reset origin/develop --hard

这里有一种方法可以做到这一点:

git checkout where-you-should-have-made-your-feature-branch
git branch feature-branch
git checkout feature-branch
foreach commit in commits-that-should-have-been-on-your-feature-branch:
    # do this for each commit in chronological order
    git cherry-pick commit

现在,这取决于您是否已经将开发分支推送到公共存储库。如果所有内容仍然是私有的,并且您想重写历史记录:

git checkout develop-branch
foreach commit in commits-that-should-have-been-on-your-feature-branch:
    # do this for each commit in reverse chronological order
    git rebase --onto commit~1 commit develop-branch

如果您不想重写历史记录:

git checkout develop-branch
foreach commit in commits-that-should-have-been-on-your-feature-branch:
    # do this for each commit in reverse chronological order
    git revert commit

这应该可以做到。

最新更新