
To get out of detached HEAD-state, you need to reattach HEAD to a branch ( master, here). You then made a third commit, which, as expected, still left you with a detached HEAD your master branch still points to the second commit. Even git log -decorate, for a long time, gave you no clue as to whether HEAD was pointing to master, or detached and pointing directly at master's tip. Some IDEs may not give you a clear indication that you are in fact in detached-HEAD state. The fact that HEAD points to the same commit as master changes nothing about the fact that your HEAD is detached. That is the definition of "detached HEAD". Note that HEAD is now pointing directly to a commit, not to a branch. Checking out a commit that happens to be the tip of a branch is not equivalent to checking out that branch! I checked out a commit/branch from master īe careful. This still left you in detached-HEAD state: Then, similarly, you checked out your second commit (which happened to be the tip of your master branch). Somehow, you checked out your first commit, which put you in detached-HEAD state: After creating your first two commits, you were in the following situation: first commitġ7:18:26.999: cd C:UsersjiahaoIdeaProjectstestttsrcġ7:18:26.999: git -c core.quotepath=false commit -only -F C:UsersjiahaoAppDataLocalTempgit-commit-msg-0.txt - C.javaĬlose inspection of the IntelliJ-IDEA log reveals the nature of the problem. If you want to create a new branch to retain commits you create, you mayĭo so (now or later) by using -b with the checkout command again.

State without impacting any branches by performing another checkout.

You can look around, make experimentalĬhanges and commit them, and you can discard any commits you make in this first commitġ7:09:38.060: cd C:UsersjiahaoIdeaProjectstestttsrcġ7:09:38.060: git -c core.quotepath=false commit -only -F C:UsersjiahaoAppDataLocalTempgit-commit-msg-0.txt - C.javaġ7:09:44.136: cd C:UsersjiahaoIdeaProjectstestttsrcġ7:09:44.136: git -c core.quotepath=false checkout 22d1c7919eab50925411d9bbb8a9ad1575608c27 Initialized empty Git repository in C:/Users/jiahao/IdeaProjects/testtt/src/.git/ġ7:09:16.331: cd C:UsersjiahaoIdeaProjectstestttsrcġ7:09:16.331: git -c core.quotepath=false add -ignore-errors - C.javaġ7:09:24.407: cd C:UsersjiahaoIdeaProjectstestttsrcġ7:09:24.407: git -c core.quotepath=false commit -only -F C:UsersjiahaoAppDataLocalTempgit-commit-msg-0.txt - C.java IntelliJ IDEA's console shows: 17:08:58.143: cd C:UsersjiahaoIdeaProjectstestttsrc Try to commit it prompts there is a detached head. Create a new project and create git repository.After that, I committed it, but I ended up with a detached HEAD. When you create branches the intent is to make changes and then you can pull the changes from remote branches into the master branch.I checked out a commit/branch from master, and then checked out back to master and wrote something. In simpler terms get is meant to make multiple copies of your project where a remote version is the source of truth and the external versions are the working copies. You could also use a branch name which is the same as using the commit hash of the head for that branch.

Will make your version of file exactly the same as the one from the commit hash. The checkout command can also be used to change the local version of your file to a version from any specific commits. It get check out followed by a branch name can make your current working directory the same as what is on the remote machine. Depending on if the gits repository it has a remote origin, when you create a branch and push it it puts it on to a remote machine. The checkout command behaves in a few different ways. Secondly, I have written my title in that way because when I read about this detached head message, it is said that people rarely get that message.Īm I missing any step? I am sure this is an extremely basic issue but this is my first day in git. Why is the master not pointing to the HEAD which is the latest file revision? New changes to FileAġ file changed, 1 insertion(+), 1 deletion(-) commit *** (origin/master, master)Ĭommitted it: git commit -m "New changes to FileA"Īnd in the output, I am already getting detached HEAD message.

I have an existing file on my local repo called FileA.
