Reputation: 42652
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
?
Upvotes: 0
Views: 89
Reputation: 129744
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.
Upvotes: 0
Reputation: 301477
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
Upvotes: 0
Reputation: 10101
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.
Upvotes: 1