-1

When I switch from Develop branch to a previously submitted, the head branch is my current branch,but the branch is not shown in my branch list (CMD: git branch).

When I finished some work,I don't be careful switch directly to Develop branches,oh my God,I lost these changes, how can I find just the part of change?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
onedotM
  • 13
  • 4
  • 2
    Possible duplicate of [How to move HEAD back to a previous location?](http://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location) – CodeWizard Apr 24 '16 at 16:40
  • 1
    Please phrase your question in a more clear way. Its not clear what you did – CodeWizard Apr 24 '16 at 16:43
  • I solved the problem(git reflog git checkout HEAD@{...} ) – onedotM Apr 25 '16 at 08:15
  • I can't make good use of stackoverflow, I will study hard.In addition, I must learn English well.Now, I can only rely on translation software. – onedotM Apr 25 '16 at 08:16

3 Answers3

0

You can use git reflog to identify where your working copy was previously. Once you've identified the relevant commit, you can just do git checkout <commit> to get back to it.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • Or `git reset ` to reset the branch to what `HEAD` was before being "lost" ? OP's a bit unclear imho – Gregory Pakosz Apr 24 '16 at 17:00
  • @GregoryPakosz - That would reset `develop`, which probably isn't what's wanted. It's most likely that the OP will want/need to create a separate branch pointing at that commit. – Oliver Charlesworth Apr 24 '16 at 17:00
0

Use the reflog to find out what happened and then recover to that point


git reflog

You can always use the reflog as well.
git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.

Every time the HEAD is modified there will be a new entry in the reflog

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit

enter image description here


How to find and restore added content (even if it was not commited )

Use the git fsck to find out about all the lose object (dangling) and then you can check them out with the git cat-file -p <sha-1> and restore them.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
0

git reflog git checkout HEAD@{...}

Thank you all.

onedotM
  • 13
  • 4