I'm using git-flow for my projects, and have started a rather complicated set of changes in the develop branch, which appear to take longer than I expected first.
I wish I had done this in a feature branch, since I'd like to make a new release with other changes. How can I move these uncommitted changes into a new git-flow feature branch?
The "merge" command is used to integrate changes from another branch. The target of this integration (i.e. the branch that receives changes) is always the currently checked out HEAD branch.
If you've made no commits
If you simply have a dirty working copy, just act like you are about to start a new feature:
git flow feature start awesomeness
git commit -va
If you did make some commits
If there are commits in develop that should have been in your feature branch, the above steps are the same. In addition though you'll (possibly - this isn't required) want to reset your develop branch back to where it was before you started committing the changes for your feature branch, which you can do with:
git flow feature start awesomeness
git commit -va
git checkout develop
git reset origin/develop --hard
Here's one way to do it:
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
Now it depends on whether you've already pushed your develop branch to a public repository or not. If everything is still private, and you want to rewrite history:
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
If you don't want to rewrite history:
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
And that should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With