sujithvm
sujithvm

Reputation: 2411

Git move commits to different branch, and make master same as upstream master branch

I was making a pull request and master got merged I didnt move to a different branch because of which few commits were added to master branch and later on I moved to branchA and added more commits for a different pull request. Now can I can remove the commits and revert back to upstream main but save the commits in different branch.

|
|  
. (master merged with upstream repo)
|
|
|
. (pull request - pr1)
 \  (new branchA)
  \
   |
   |
   . ( pull request - pr2)

The new branch contains commits from the unmerged master branch. How can I remove the commits and make a new branch. This is what I want

|
|  
. (master merged with upstream repo)
 \  \
  \   \
   |    | 
   |    |
   |    |
 (br-   |
anchB)  |
 pr1     (branchA) pr2

Any pointers to how this can be achieved? Thank you

Upvotes: 2

Views: 70

Answers (1)

manzur
manzur

Reputation: 692

If I understand correctly, you want to move your branch2 to the earlier of the master and apply commits you had changed since branch1. If so, you should do the following:

git checkout -b branchB 
git reset --hard <commit want to change>

or switch just two commits back(if the picture is right):

git reset --hard branchA^^

Upvotes: 1

Related Questions