3

I created a new project that included some folders that already had a git repository.

Edit: inner git repositories were not uploaded somewhere online and no commits where made in them, only in the main repo

When i added all the files with git add --all for the initial commit and pushed them to bitbucket the inner git tracked folder was not present in the s but instead a link-like entry was listed with an alphanumeric like a sha hash like

<folder name> → 031c27df078f [031c27df078f]

After some confusion i had i ended up deleting my local files with the changes and the .git subfolder in the submodule.

I tried hard resetting to the first commit i had but no files were reverted.

Is there any way to get my changes back from my main git repo or are they forever lost?

Is there a way to push all folders including submodules?

eltonkamami
  • 5,134
  • 1
  • 22
  • 30

1 Answers1

2

the inner git tracked folder was not present in the s but instead a link-like entry was listed with an alphanumeric like a sha hash

Those were not submodules but simple gitlink (special entries in the index) representing the nested git repo SHA1.
See "Difference between nested git repos and submodules".

Is there any way to get my changes back from my main git repo or are they forever lost?

At least clone back your repo (the one where you pushed gitlinks + your code): you will find your changes there.

Then start over in a new repo, and force push.


is there any way to get the inner repo(which now is a link) to the state it was when i pushed the code to bitbucket?

You have the SHA1 of those inner repo, and hopefully you have their url.

So in your brand new repo, once you have added and committed your own code, add those repos as submodule this time:

 cd /path/to/new/repo
 git submodule add -- /url/repo1
 cd repo1
 git checkout <SHA1>
 cd ..
 git add repo1 # no trailing slash
 git commit -m "add repo1 as submodule"
 git push -u origin master

However, the OP does mention:

I still have the files in the initial state. But all my changes were done in the pasted one. Another big mistake was that my only commit was on the main repo when i created it. The inner one was in the initial state.

In that case (absence of the inner .git folder), those chances are probably lost.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • the changes from my main repo are there but is there any way to get the inner repo(which now is a link) to the state it was when i pushed the code to bitbucket? – eltonkamami Feb 14 '16 at 19:59
  • @antoniskamamis Sure. I have edited the answer to address that. – VonC Feb 14 '16 at 20:02
  • my bad explaining but i havent got the inner repo somewhere online. does bitbucket upload it for me? – eltonkamami Feb 14 '16 at 20:04
  • @Bitbucket did not register those repos url. Only their SHA1. Are those repos only local repos on your computer? – VonC Feb 14 '16 at 20:05
  • i had copy pasted them in my project. then accidentaly i deleted the whole folder including .git subfolder. my only hope was if the outer git repo was tracking the inner one two so i can get my files back – eltonkamami Feb 14 '16 at 20:07
  • @antoniskamamis copy-paste? so they still exist outside the repo? – VonC Feb 14 '16 at 20:08
  • i still have the files in the initial state. but all my changes were done in the pasted one. another big mistake was that my only commit was on the main repo when i created it. the inner one was in the initial state – eltonkamami Feb 14 '16 at 20:10
  • @antoniskamamis without the original .git folder, there will be little chance to recover the changes (especially if said changes were not even added to the index of those repo) – VonC Feb 14 '16 at 20:26
  • this http://stackoverflow.com/questions/5980960/git-repository-in-a-git-repository makes it clear i think that changes are lost – eltonkamami Feb 14 '16 at 20:38
  • @antoniskamamis I agree. Unless you use some sort of file system recovery third-party program, those changes are lost. – VonC Feb 14 '16 at 20:43