1

I have lost all project data in git from all branches and I'm unable to recover it.

I created three branches: 'master', 'distribution' and 'remoteerp' (All with same code and just backup) and checked-out to remoteerp, then I configured the sparse checkout config as true and updated /.git/info/sparse-checkout file to /inoERP/inoerp/www/ and /inoERP/inerp/inoerp-server. Then, I pulled my fork-project from github like this:

git remote add -f githubinoerp [github_url_to_my_fork_repo]
git pull githubinoerp master

Which caused conflicts in License.txt and Copyright.txt and showed only these files in working directory. As I'm not able to resolve merge-conflicts (I am still studying git as beginner), I just tried to reset to old state using git reset --hard however it changed nothing accept saying something like sparse-checkout has changed your working directory. Checking out to other branches (like distribution and master) subsequently is also not showing the original files. i have tried git reset Head -- hard and git reset --hard on (after checking out) all branches but no use.

how can i recover my project to older state?

Víctor López
  • 819
  • 1
  • 7
  • 19
Fakhar Anwar
  • 295
  • 1
  • 3
  • 20
  • If you're still a beginner you should probably stay away from advanced features such as sparse checkouts. – Lasse V. Karlsen Aug 22 '17 at 12:36
  • Alas i could do that but i am experimenting with inoERP which has a different directory structure of dustribution (after installation) as compared to its repo on github and i wanted to download and checkout only a subdirectory of repo which is actual code. – Fakhar Anwar Aug 22 '17 at 13:08

2 Answers2

6

You are still in the sparse checkout mode, that's why you don't see your files.

Run the commands:

git config core.sparseCheckout false
git read-tree --empty
git reset --hard

This should restore your checkout to full.

max630
  • 8,762
  • 3
  • 30
  • 55
  • I am using the instructions here: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository and getting the error: Sparse checkout leaves no entry on working directory. That is exactly what i got earlier than loosing all files from my work directory earlier. Note: My local directory is 'myerp' and my remote name is 'githubinoerp' What is wrong / missing with those instructions? causing issues. – Fakhar Anwar Aug 22 '17 at 14:54
  • Here is screenshot of my screen: https://www.screencast.com/t/IuQc3gxU – Fakhar Anwar Aug 22 '17 at 15:00
  • This message means your patters did not match any of the file. Search for it here, there are plenty questions about it. As far as I understand you no longer need sparce checkout. What are you trying to achieve? – max630 Aug 22 '17 at 17:44
0

It seems you have to learn to merge-conflicts. Conflicts are very common on team projects, so It's something you probably will use in the future.

Here you have a very good manual to resolve conflicts: https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/

Anyway, you can check your previous status with something like that:

git checkout hash-commit

You can get the hash using git log (after "commit").

It's a very comfortable way to check in which part fail something.

Edit: You used git reset --hard, but maybe it was not the last commit the problem. You could use git reset --hard hash_commit. You should not use this if you didn't check the commit before, because you can't undo this.

Víctor López
  • 819
  • 1
  • 7
  • 19
  • not working even now, th working directory is still missing all project files; same situation as before. Screenshot: https://www.screencast.com/t/nc3PCgZ2LNnk – Fakhar Anwar Aug 22 '17 at 13:04