I commit to a git repository for the first time; I then regret the commit and want to revert it. I try
# git reset --hard HEAD~1
I get thi
This question was linked from this blog post and an alternative solution was proposed for the newer versions of Git:
git branch -m master old_master
git checkout --orphan master
git branch -D old_master
This solution assumes that:
master
branchold_master
so I'm free to use that nameIt will rename the existing branch to old_master
and create a new, orphaned, branch master
(like it is created for new repositories) after which you can freely delete old_master
... or not. Up to you.
Note: Moving or copying a git branch preserves its reflog (see this code) while deleting and then creating a new branch destroys it. Since you want to get back to the original state with no history you probably want to delete the branch, but others may want to consider this small note.