Reputation: 15974
I have branch master and branch dev. I started a feature branch from master by mistake. Meaning, I did git checkout -b feature-branch
while I was on master.
Now I want to merge the feature branch on branch dev. How do I do it?
Upvotes: 1
Views: 56
Reputation: 932
If there are not too many commits, then "git cherrypick" is an option:
EDIT: I added an example how to do the same with "git rebase" command:
You can also use the branch~N syntax instead of the commit hash if you are not afraid of counting commits ;) Although it just one command, I would still use the first option, because it it takes quite a bit more effort to get it right (i.e. check the manual, select the right command line arguments). So it would make sense only for moving longer topic branches.
Upvotes: 1
Reputation: 116
You can use 'git log' to find the point before you started your work and then use 'git diff' to find the difference between the current HEAD and that point. 'git apply' will apply that diff.
On your feature branch, use git log to find the start of your work. Record the commit before your work.
git checkout feature-branch
git log
Store the difference between the point you found above and your work (the current HEAD revision). HEAD is an implied argument.
git diff (commit_from_step_above) > patch.txt
Apply your change to a correct feature branch.
git checkout dev
git checkout -b proper_feature-branch
git apply patch.txt
(add, commit, etc)
If others have changed the same files you're changing, you'll have a merge conflict. This is expected.
Upvotes: 0
Reputation: 847
to merge the commited changes that you've made from one branch
to another you could use: git merge <branchname>
. Let me set you an example:"
I want to merge the changes i've made on branch dev
with my master branch
. The first thing i'll do is commit the changes on branch dev
then i'll switch to branch master
and i will merge the changes from the dev
branch by using:
git merge dev
So step by step: first commit your changes from the development branch.
git commit -m "<commit message>"
Step two: Switch to the master branch
git checkout master
Last step: merge your changes from the dev
branch/
git merge dev
Hope this helps!
Upvotes: 0