Rollback to an old Git commit in a public repo
Try this:
git checkout [revision] .
where [revision]
is the commit hash (for example: 12345678901234567890123456789012345678ab
).
Don't forget the .
at the end, very important. This will apply changes to the whole tree. You should execute this command in the git project root. If you are in any sub directory, then this command only changes the files in the current directory. Then commit and you should be good.
You can undo this by
git reset --hard
that will delete all modifications from the working directory and staging area.
To rollback to a specific commit:
git reset --hard commit_sha
To rollback 10 commits back:
git reset --hard HEAD~10
You can use "git revert" as in the following post if you don't want to rewrite the history
How to revert Git repository to a previous commit?
Well, I guess the question is, what do you mean by 'roll back'? If you can't reset
because it's public and you want to keep the commit history intact, do you mean you just want your working copy to reflect a specific commit? Use git checkout
and the commit hash.
Edit: As was pointed out in the comments, using git checkout
without specifying a branch will leave you in a "no branch" state. Use git checkout <commit> -b <branchname>
to checkout into a branch, or git checkout <commit> .
to checkout into the current branch.