2

I have an issue using Git. I made some changes to my files and checked out to new branch using

git checkout -b new_branch

Actually I haven't committed code in old branch. I have moved to old branch and reverted changes thinking those changes are available in new branch. Is there any chance to restore the uncommitted changes in either of the branches? I tried git reset --hard too.

Here is my git reflog output

764d2e2 HEAD@{1}: checkout: moving from old_branch to new_branch
c5726a6 HEAD@{2}: checkout: moving from new_branch to old_branch
c5726a6 HEAD@{3}: reset: moving to HEAD@{2}
c5726a6 HEAD@{4}: checkout: moving from old_branch to new_branch
c5726a6 HEAD@{5}: checkout: moving from new_branch to old_branch
c5726a6 HEAD@{6}: checkout: moving from old_branch to new_branch
max630
  • 8,762
  • 3
  • 30
  • 55
0x52616A657368
  • 388
  • 3
  • 24

1 Answers1

3

I believe git checkout, if you did not specify --force, should keep changed files or fail in case they are also different between branches, so you should be able to commit them to whatever branch is current.

But you have run git reset --hard, and this is much worse, because it definitely discards uncommitted changes. I'm afraid it is not possible to restore them now.

If you had staged them as VonC described, you could use search through dangling blobs to find changed files.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
max630
  • 8,762
  • 3
  • 30
  • 55