0

My scenario is as follows. I created a feature branch off of the master, made and committed changes to it locally. After this the Repo was reorganized before I could push and merge my changes. Now, feature branches are to be created off of a newly created develop branch and not master. As part of the reorganization my branch was deleted from the server. I have not yet fetch(ed)/Pull(ed) from the server. What I want to attempt is move my committed changes from the now deleted branch to a new Feature branch that I will create from the develop branch. I am using Bitbucket. master --> old branch with changes (deleted from server but available locally) to develop --> new feature branch ( to be created )

1 Answer 1

1

let's assume your local old branch is old-branch, the new feature branch you want to create is new-branch (you didn't create it yet), the old base branch is master and the new base branch is dev and let's assume your working directory is clean and remote name is origin and lastly, let's assume hash of your first commit in old-branch is [first-hash] and your last commit is [last-hash] (you can find them by running git log old-branch). so this should fix your problem:

git fetch origin; git checkout dev; git pull origin dev; git checkout -b new-branch; git cherry-pick [first-hash]^..[last-hash]; # pay attention to the ^ sign! 

Now the new-branch is the exact copy of old-branch.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for responding ... I got till the git fetch origin step ... When I tried to checkout dev(elop) ... Got an error saying Please commit your changes or stash them before you switch branches. Aborting ... Seems strange to me since I do not have any un committed changes ... Checked in VS as well ... Nothing to Stage or Commit
Never mind my previous comment ... Looks like a glitch in VS ... Did not show any changes ... Restarted it and started showing unstaged changes ... Continuing with the rest of the steps ... Will update once done and mark it as an answer if things work out ...
That message means your working directory is not clean. you can commit them or discard them by git checkout . and check what's the changes by git diff

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.