'Checked out previous git commit, now can't switch back to HEAD
In my React Native project I checked out a previous git commit using git checkout <previous commit SHA>, then tried to return to HEAD using git checkout <most recent commit SHA>. It said error: Your local changes to the following files would be overwritten by checkout: android/gradlew.bat. Please commit your changes or stash them before you switch branches.
I did git stash and then git checkout <most recent commit SHA> again, but it gave me the same Your local changes error.
How can I get back to HEAD?
Solution 1:[1]
Assuming you do want to keep your changes (otherwise just git reset --hard HEAD), you could switch to a new branch (git switch -c [new name here]), commit the changes there, then head back to your main and perform a hard reset to HEAD as mentioned above. I'm not sure why the stashing isn't working for you, but this should save your changes in the new branch, bring you back to HEAD in main, and allow you to then merge in your branch with the changes however you see fit (a rebase might be in order).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Connor Mooneyhan |
