Reset a remote branch to previous commit 1

Reset a remote branch to previous commit

git reset --hard HEAD^

Here is what the above code is Doing:
1. git reset –hard HEAD^
This command will reset the current branch to the previous commit.
The –hard flag will also reset the working directory to match the commit.
This means that any changes you’ve made to the working directory will be lost.
The HEAD^ syntax is a shortcut for HEAD~1, which means the commit before HEAD.
You can also use HEAD~2 to go back two commits, and so on.
2. git push origin +master
The + tells git to force the push.
This is necessary because you’re pushing a commit that’s not a direct ancestor of the commit on the remote branch.
If you don’t force the push, you’ll get an error.

Similar Posts