Taking into consideration that there are several git commands that make no sense in a bare repository (because bare repositories don't use indexes and do not have a working directory),
git reset --hard HEAD^
is not a solution to uncommit the last change in such a repository.
Searching through the Internet, all I could find related to the topic is this, in which I am presented three ways of doing this:
1. "update the ref manually (which involves plumbing)";
2. "git push -f
from a non-bare repository";
3. "git branch -f this $that
".
Which solution do yo think is more appropriate or what other ways are there to do this? Unfortunately, the documentation I found about git bare repositories is fairly poor.
If you use the following in a bare repo:
then you don't run into the issues you have using
--hard
and--mixed
options in a bare repo since you're not trying to change something the bare repo doesn't have (i.e. working tree and index). In your case specifically you would want to use (from the bare repo):To switch branches on the remote repo do:
You can also use git refspec notation and do something like this:
git push -f origin +<commit you want to revert to>:<destination_head | branch_name>
This forces update of destination branch (as denoted by the ref) to the source commit as denoted by the
+<object ref>
part.The
git push -f
should work fine:if you clone that bare repo, remove the last commit (
git reset --hard HEAD^
as you mention, but in a local non-bare repo) and push back (-f
):You can use the
git update-ref
command. To remove the last commit, you would use:Or if you're not in the branch from which you cant to remove the last commit:
You could also pass a sha1 if you want:
See the documentation of the git-update-ref command.