将开发更改移动到新功能分支

pad*_*bro 5 git git-merge git-flow git-branch

对于我的项目,我使用git-flow.我masterdevelopremote-repo同步分支通常对于所有更改我创建一个feature分支,编辑文件,在feature分支上提交更改并通过合并关闭分支develop.

但有时我忘了创建一个feature分支,我直接编辑文件develop.如何在新的feature分支中移动canges ?

cmb*_*ley 11

如果您已经提交了develop,您的历史记录如下所示:

A---B---C---D develop
Run Code Online (Sandbox Code Playgroud)

C是最后一次正确的提交develop,D应该已经提交给功能分支.执行以下操作(启用时develop):

git branch feature      # creates feature branch pointing at D
git reset --hard C      # or HEAD^, HEAD~1, etc - resets develop back to C
Run Code Online (Sandbox Code Playgroud)

这将导致:

A---B---C develop
         \
          D feature
Run Code Online (Sandbox Code Playgroud)

如果您进行了多次提交,这也可以正常工作,因为您可以develop在第二个命令中替换需要重置的提交引用.