let's say that we have an hotfixes
branch which was created from master
. we added commits to hotfixes
, but those commits were not useful, so now we want to start from a fresh copy of master
again.
to clarify better, this is the reference workflow: http://nvie.com/posts/a-successful-git-branching-model/
let's also say that we pushed hotfixes
to the origin
remote because we have an awful set up and that's the only way to test something, so we need to reset the branch also on the remote server.
how to reset hotfixes
to a copy of master
?
(It does not affect the working tree or the current branch.) This means that git reset <pathspec> is the opposite of git add <pathspec> . This command is equivalent to git restore [--source=<tree-ish>] --staged <pathspec>... .
this is how i did it with basic Git commands:
git checkout hotfixes git reset --hard master git push --force origin hotfixes
of course it's important to notify everyone working on hotfixes
. most likely they will have to delete their local copy and start from a fresh one. an alternative, less invasive idea is to create a new branch:
git checkout master git branch -tb hotfixes-2 # this creates branch `hotfixes-2` from a copy of `master` git push origin HEAD # this creates `hotfixes-2` on the remote server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With