-
Notifications
You must be signed in to change notification settings - Fork 22
Resetting a Branch
If you've found yourself on this page, someone has probably asked you to reset your branch.
What this means is that you need to roll back on the commits you've made recently, because something you changed was not mergeable, and the fastest way to fix that is to delete the change and start over.
First, run:
git log --format=oneline
Find the first seven or so characters in the commit ID for the commit you want to roll back to, then hit q to exit the log.
To roll back the commits do something like:
git reset --hard 63ab2de^
This will delete all the commits up until and including the commit with ID 63ab2de
. (The ^
symbol is shorthand for "the commit before the listed one". This is why this command includes a rollback of 63ab2de
. If we wanted to roll back all commits after 63ab2de
, we'd use git reset --hard 63ab2de
, without the carat.)
Check out your git log
to make sure everything is in good order. If things look right, we'll rewrite our remote history by running:
git push --force origin HEAD
We must use the --force
flag, since git will not permit us to rewrite history without telling it that we're really sure about it.