GIT forgot to branchout from master before working on a new branch working directory

Viewed 29

so I have 3 branches

master
dev_1
dev_2

I have pushed my changes in dev_1 ang already create a pull request, now when I worked on dev_2 branch I did not branch-out from master branch so my working directory also has changes from dev_1 which is not what I want.

I just found out about this when I already merged develop to(>) dev_2 and pushed my changes in the remote repository for dev_2. How do I undo all changes in dev_2 that was created from dev_1 in my local working directory and in the remote repository?

1 Answers

Create a "dev_3" from master and then cherry pick those dev_2 commits you want using "git cherry-pick" - I usually do it one-by-one but you can supply a range. You probably don't want any "merge" commits - just those with real changes. Once you have done that, abandon dev_2. Basically that is it.

One variation is to start from an earlier version of master if you think master has moved on so the cherry-picks would require a lot of manual editing otherwise. You can create the branch from any commit if you need/want to, but in this case you should only use something that has been "master" in the past.

Related