Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move modifications made in develop branch into a new git-flow feature branch?

Tags:

git

git-flow

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?

like image 581
plang Avatar asked May 22 '12 15:05

plang


People also ask

Which command is used to integrate changes from one branch to another 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.


2 Answers

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
like image 108
AD7six Avatar answered Oct 06 '22 08:10

AD7six


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.

like image 41
Neil Forrester Avatar answered Oct 06 '22 08:10

Neil Forrester