Reputation: 29
I had two different branches, let's say branchA and branchB. I checked out to branchB and made changes in featureB. In addition to featureB, I made the required changes of featureA too! Now I want only the featureB changes to be pushed in branchB, and only the featureA changes to be pushed to branchA. Please help!
Upvotes: 0
Views: 47
Reputation: 164679
You have this.
C - FB - FA [branchB]
/
A - B [master]
\
D - E [branchA]
A, B, C, etc are just some commits. FA and FB represent the commits for feature A and feature B.
You want this.
C - FB [branchB]
/
A - B [master]
\
D - E - FA [branchA]
There's several ways to handle this. Here's one.
First, cherry-pick the feature A changes into branchA. This will copy the commit. There may be conflicts.
git checkout branchA
git cherry-pick FA
C - FB - FA [branchB]
/
A - B [master]
\
D - E - FA [branchA]
Then eliminate the commit (s) from branchB using an interactive rebase.
git checkout branchB
git rebase -i master
An editor will come up. Delete the lines with the offending commits and Git will rewrite the remaining commits in branchB on top of master.
C - FB [branchB]
/
A - B [master]
\
D - E - FA [branchA]
See Rewriting History in the Git Book for more.
Upvotes: 2