2

Below is the situation which explains what's the matter about git.

  1. I was using the 'develop' branch and already made several changes to the local files such as .sql, .java, .js...

  2. I made a local branch called 'develop_some_future' since my boss wants to confirm my changes before merging main 'develop' repository.

  3. Apparently my local file changes @'develop' branch have applied to 'develop_some_future' branch and I started editing local files again.

  4. For some reason, I tried to pull the files that my co-workers already committed, but it has failed(Probably I couldn't set 'develop_some_future' branch well). So, I changed current branch to 'develop' branch and tried to pull them.

  5. Fortunately it got worked, and then I tried to back to the 'develop_some_future' branch.

  6. A dialog pops up suddenly while changing the branch and asked me that 'your local change for "~~~.sql" would be deleted since it's not committed yet. To avoid this, please commit that file or choose reset.'

  7. Because I thought only '~~~.sql' would be changed to the latest committed state and that was not a problem, I selected 'reset' button, but unfortunately all local changes have gone.

Anyone knows how can I retrieve the date before reset?

I found that both 'git reflog' and 'git reset HEAD{}' commands are useful. However, git reflog shows only commit, merge, and checkout changes and so I can't find reset status at all.

TZHX
  • 5,291
  • 15
  • 47
  • 56
REI
  • 404
  • 2
  • 5
  • 17
  • You are in a big mess, and for this reason I don't recommend that beginner Git users use the Eclipse plugin (or any other plugin). If you committed the `.sql` files in question, then `git reflog` should show those commits somewhere. If you really never committed the changes anywhere, they may very well be lost. – Tim Biegeleisen Jun 08 '15 at 09:35
  • Thanks Tim. Now, this is a big failure since I didn't commit any files... – REI Jun 08 '15 at 09:40
  • Switch to the `develop_some_future` branch and type `git log`. See if your changes are present there. – Tim Biegeleisen Jun 08 '15 at 09:42
  • I can see only committed changes by my co-workers @'develop' branch. Maybe I screwed up totally. – REI Jun 08 '15 at 09:46
  • Please read this SO post: http://stackoverflow.com/questions/11094968/in-git-how-can-i-recover-a-staged-file-that-was-reverted-prior-to-committing – Tim Biegeleisen Jun 08 '15 at 09:48
  • Thanks, but I can't see dangling blob anywhere on terminal I typed 'git fsck --lost-found ' at my project directory though. – REI Jun 08 '15 at 10:00

1 Answers1

1

I'm afraid your files are gone for good, unless you had previously staged the file somehow (add or stash save).

If it had been staged, a blob object was created by Git which is now dangling (git fsck will tell you dangling objects). You can then resurrect the file by writing the blob's content with git cat-file to a new file.

If not, your'e screwed, and you have to do your work again.


It seems the problem arose in the first place, because you thought that unstaged/uncommitted changes belong to the current branch. They do not, and only live in the working directory. They will be carried over when switching branches (unless, of course, the same file was modified in the branch. Git will then refuse to checkout the other branch).

knittl
  • 246,190
  • 53
  • 318
  • 364