0

I was working on master branch.

I have made many changes on my project, then commit & pushed all the changes to remote repository by:

git push origin master 

Then, I made a new branch, and push the latest code to the new branch (to make it a remote branch) like following:

git branch new-branch git checkout new-branch git push origin new-branch 

I am now on new-branch. Now, both master & new-branch have the same latest code locally & remotely.

My question is:

How can I revert the change back on master branch both locally and remotely. But keep all the changes only on new-branch ?

3 Answers 3

1

Go to the master branch and do a git revert HEAD and git push origin master. This will create a new commit that reverses the commit you want to undo.

You could also do a git reset --hard HEAD^ (on the master branch) and a git push -f origin master (-f to force the push), but if anyone pulled the latest changes that you pushed it would cause problems for them.

The changes on the new-branch shouldn't be affected by these operations.

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

Comments

0

Since you have pushed it, the ideal way would be to git revert the commit in master and push master:

git checkout master git revert HEAD git push origin master 

The above will create a new commit which is the revert ( undoes the changes) of the previous

Comments

0

This assumes you are already on your new branch.

git push . +master^:master git push origin +master 

This will allow you to not bother even checking out master in order to roll it back both locally and remotely.

Be careful in case someone is already working off of master. They will have to rebase their changes on top of the other commit if they want to push their changes.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.