Gary
Gary

Reputation: 395

Bitbucket - Commiting to a new Branch caused issue, not sure how to fix

This is the order of actions which caused this problem.

  1. Branch created from Master, branch name v1
  2. Changes made to this new Branch and pushed
  3. I pulled this Branch (after push) and made some changes as well
  4. Another user made some changes and pushed (before me)
  5. Decided to make a Branch off that Branch, v1_adminui
  6. sent a git fetch to get the new Branch and issued a git checkout v1_adminui
  7. git checkout v1_adminui complained that I need to commit first because v1_adminui has some files edited which I was working on
  8. I issued git add --all and git commit -a -m "Changes to Admin UI" then did the git checkout v1_adminui
  9. Now I'm on v1_adminui but I don't have my admin ui commit changes

How do I get my admin ui changes to v1_adminui? It looks like the commit happened to v1 so now I'm stuck... Any help would be great please.

Note that I can't push that commit, it needs to be reviewed first before merging.

Upvotes: 0

Views: 34

Answers (1)

mcwayliffe
mcwayliffe

Reputation: 426

This should be a fairly straightforward fix. First, look at the documentation for git cherry-pick here. Then, when you understand what that's doing, take the following actions:

First, delete your local v1_adminui branch, since it is, at this point, exactly the same as your v1 branch.

git checkout v1
git branch -D v1_adminui

Next, checkout the commit before you added all your adminui stuff

git checkout HEAD~1

Now, make a "new" v1_adminui branch from that commit

git checkout -b v1_adminui

Next, grab the commit you want from your local copy of v1 (this assumes that commit is on top of your v1 branch.

git cherry-pick --no-commit v1

Now, your index will look as if you had made all of your adminui changes on your v1_adminui branch, but haven't yet committed. Commit those changes:

git add -A
git commit -m "<some-message-here>"

Now, your v1_adminui branch will have all the changes that you wanted to have there.

Lastly, if you want your v1 branch NOT to have those changes, go back to it

git checkout v1

and reset them (this assumes that you only made one commit that you no longer want there.

git reset --hard HEAD~1

Make sure you are careful with reset --hard (check docs here)

Upvotes: 1

Related Questions