4

I ran the following set of commands inside my local repo (branch develop) to try to git a subdirectory (assets/App) in my project to link to a remote repo's App directory, so that when they update code, I can get those updates without having to copy/paste from a clone:

git remote add durandal git://github.com/BlueSpire/Durandal.git
git fetch durandal    #now I have a remote branch with all of Durandal
git checkout -b durandal durandal/master    #now I have a local branch with the contents of durandal/master and have switched to it
git config core.sparsecheckout true    #trying some sparse-checkout stuff, not really understanding what I'm doing
echo App/ > .git/info/sparse-checkout
git checkout develop     #back in my develop branch
git read-tree --prefix=assets/App/ -u durandal     #all hell breaks loose

At this point, all my files were gone from branch develop except for assets/App/ (and those files that were in .gitignore) which now has the contents copied from the durandal branch App folder. I immediately ran git reset --hard to no avail. I tried resetting with a sha. Nope. I tried pulling from my dropbox remote that should have had everything backed up. Same deal. I tired switching to master and all the files were gone from there too, which I completely don't understand. I can't see how to recover.

I know I should not have done this without really understanding what I was doing but can someone help me get my repo back to where it was prior to my experiment? Secondarily, what did I do to cause this and how might I accomplish what I was trying to do?

neverfox
  • 6,680
  • 7
  • 31
  • 40

1 Answers1

1

Going from basics (I've never looked at sparse checkout beyond vaguely knowing it exists) I'd try

rm .git/index
rm .git/info/sparse-checkout
git config core.sparsecheckout false
git checkout develop@{yesterday}      # `man gitrevisions` docs the @{} syntax

but hopefully someone who's actually been where you are can say for sure whether that'll work.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • It worked! Thank you! I actually didn't need to run the last command as I noticed my stage now showed all of my missing files marked as ready to delete. I `git reset --hard` and was back to normal. I learned that the best way to accomplish what I was after can be done simply and safely with [sub-tree merging](https://help.github.com/articles/working-with-subtree-merge). – neverfox Mar 04 '13 at 20:37