将在develop分支中所做的修改移动到新的git flow功能分支中?

将在develop分支中所做的修改移动到新的git flow功能分支中?,git,git-flow,Git,Git Flow,我在我的项目中使用git flow,并且在开发分支中开始了一系列相当复杂的更改,这些更改似乎比我最初预期的要长 我希望我已经在一个功能分支中完成了这项工作,因为我想在新版本中进行其他更改。如何将这些未提交的更改移动到新的git flow功能分支中?这里有一种方法: git checkout where-you-should-have-made-your-feature-branch git branch feature-branch git checkout feature-branch for

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


我希望我已经在一个功能分支中完成了这项工作,因为我想在新版本中进行其他更改。如何将这些未提交的更改移动到新的git flow功能分支中?

这里有一种方法:

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
如果不想重写历史记录:

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

如果您没有提交,就应该这样做。

如果您只是有一个脏的工作副本,就好像您即将启动一个新功能:

git flow feature start awesomeness
git commit -va
如果您确实做出了一些承诺

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

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

循环中的git rebase似乎有点不必要/笨拙-有什么想法?嗨,谢谢你的回答,但还没有提交任何内容。解决方案比这简单。我不知道在未提交的更改之后该功能可以启动。谢谢