I am new to Android Studio and have began developing a Navigation Drawer app.
After having made a mistake in a commit, I played around with the Version control's "Checkout Revision" and now I can no longer push my project onto Github due to a "Detached HEAD".
How can I fix this problem? My app runs perfectly fine in the emulator.
Thanks
If you want to keep changes made with a detached HEAD, just create a new branch and switch to it. You can create it right after arriving at a detached HEAD or after creating one or more commits. The result is the same. The only restriction is that you should do it before returning to your normal branch.
When you use the git checkout command to view a commit, you'll enter “detached HEAD state”. This refers to when you are viewing a commit that is not the most recent commit in a repository. Detached HEAD state is not an error nor is it a problem. When you are ready, you can navigate back to the HEAD in your repository.
Note that once Git prunes your detached HEAD state commits, there is no way to get them back. However, if they have not been deleted, you can check out to that SHA-1 commit hash, create a branch, and merge it to the desired branch to preserve the changes.
The Detached HEAD state warns that your activity is “detached” from the project's development. It allows checking out commits and examining the repository's older state without creating a local branch. The HEAD updates the git checkout command to point the specified branch or commit.
you can go to VCS menu then Git, Branches, then in Git Branches dialog click on item below local branches then checkout branches and then accept your default branches. it will connect your project to it's default branch and you can commit your project.
If you already made a lot of changes and want to commit and push online but out of sudden got this detached head issue, here are steps you can do for Git through Android Studio:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With