I pushed changes to a branch with a detached head using IntelliJ. It gave me an obscure warning but accepted my push without forcing. Then I checked out the branch and all my changes disappeared. Where are they and how do I get them back?
1 Answers
If you type git reflog, it will show you the history of what revisions HEAD pointed to. Your detached head should be in there. Once you find it, do git checkout -b my-new-branch abc123 or git branch my-new-branch abc123 (where abc123 is the SHA-1 of the detached HEAD) to create a new branch that points to your detached head. Now you can merge that branch at your leisure.
Generally, if you check out a branch after working on a detached head, Git should tell you the commit from the detached head you had been on, so you can recover it if you need. I've never used SourceTree, so I don't know if it relays that message. But if it did display that message, then you should be able to use that to find the commit, and again use git checkout -b or git branch to create a branch from that commit.

- 156
- 1
- 12
-
Welcome. Please If the answer is correct, click on Answers. @AlexWorden – utsav tilava Oct 16 '19 at 06:32