I want to revert the previous commit back to my project.
I tried
git checkout <hash>
but i get a detached HEAD which means that i have to create a new branch when i commit the code again after i've worked on it.
Asked
Active
Viewed 315 times
-1

lirdi
- 21
- 5
-
2`revert` has a technical meaning that is different than `reset`. It sounds like you want to reset. – William Pursell Dec 07 '21 at 18:23
-
they both work fine for me thank you – lirdi Dec 07 '21 at 18:26
-
3Does this answer your question? [How do I revert a Git repository to a previous commit?](https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit) – parkourkarthik Dec 07 '21 at 18:28
-
@parkourkarthik it partialy does but it does not answer how not to get a detached HEAD – lirdi Dec 07 '21 at 18:30
-
It does because you did `checkout`, which means : "bring me back to a specific revision of my history, so I can check it out". It will, repopulating your working dir with the files of this revision, but won't alter your history. Since you've asked for a hash and not a branch name, you're no longer tied to a branch if you commit from here, hence being in "detached mode". You come back to attached mode (tied to a branch) when you check out a branch name, which leads you back to the tip of this branch. – Obsidian Dec 07 '21 at 18:55