0

I wanted to check if my new changes to code were compatible with existing database, thus I tried to create a new branch from HEAD of remote ORIGIN.

I ran exactly the following code :

git checkout -b test origin/master

Till this time, my modified code was present in new branch. I know this because I saw similar output

M filename1
M filename2
M filename3
M filename4

I wanted to roll back changes, to the previously pushed commit, hence ran this command

git reset --hard HEAD

Running this command, reversed all the changes. I thought that happened only for this branch, but I was wrong. I did some changes to code in this branch (I edited only one file which was earlier modified in master branch)

I think this was where all went wrong, I checked out master branch using

git checkout master

I see output similar to following

M filename1
M filename2

This is where I realise all changes were lost. I have tried resetting the HEAD again but no progress.

Is there any way to recover those files, or I have to write all code again?

phd
  • 82,685
  • 13
  • 120
  • 165
pandafy
  • 184
  • 13
  • Hi, if you do not commit this changes so I doubt there is possibility to recover your changes. If your changes was commited somehow, then after reset hard, there is sstill some sym-links in objects. Try read about git fsck --lost-found – Robert Pawlak Jul 12 '19 at 15:18
  • Possible duplicate of [Undo git reset --hard with uncommitted files in the staging area](https://stackoverflow.com/questions/7374069/undo-git-reset-hard-with-uncommitted-files-in-the-staging-area) – phd Jul 12 '19 at 15:21
  • https://stackoverflow.com/search?q=%5Bgit-reset%5D+undo+reset+hard – phd Jul 12 '19 at 15:21
  • 2
    `git reset` modifies the branch. `git reset --hard` also modifies the working directory. I suspect you misunderstand what a branch is. It is literally nothing more than an alternate name for a single commit. We tend to overload it with meaning and also include all of its ancestors back to some merge-base or the root. It is somewhat dynamic, in that the commit it references changes when you make a new commit, but it is really just a reference to a single commit (and some associated metadata). – William Pursell Jul 12 '19 at 15:25
  • Thanks for information @WilliamPursell – pandafy Jul 23 '19 at 05:13

0 Answers0