0

I did the following:

  1. git clone [fork]
  2. worked for a few days, creating new files 1 & 2
  3. git add newfile1
  4. git add newfile2
  5. git checkout -b new_branch
  6. git checkout master

At this point, I expected newfile1 and newfile2 to be waiting for me, but they are not. Everything has reverted back to the original master, as what is currently on the github server.

Is my work waiting for me somewhere? Or has it become a recycled bunch of bits?

4
  • 1
    If you run git status do the new files show up as changes to be committed? Commented Dec 2, 2013 at 22:44
  • The git checkout -b master seems suspect as there should already be a master branch. Maybe there is a typo on this line and maybe there is a branch that is closely named to master that has newfile1 and newfile2. What does git branch show? Commented Dec 2, 2013 at 23:46
  • good catch, I meant that...figuratively. It was the initial git clone of the fork. Commented Dec 2, 2013 at 23:58
  • torek: no, the files do not show up to be committed Commented Dec 2, 2013 at 23:58

1 Answer 1

3

After repeating your steps my git status shows me

# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: newfile1 # new file: newfile2 # 

This mean, that you did something else to your repository, that you didn't considered important nor potentially harmful.

And now to your actual question: Yes, you might be able to do it.

  • First do a complete backup of your .git directory
  • Create a file all-objects.sh with this script (source: https://gist.github.com/ctindall/4588884)

    #!/bin/sh set -e cd "$(git rev-parse --show-cdup)" # Find all the objects that are in packs: if [ "$(ls -A .git/objects/pack)" ] then for p in .git/objects/pack/pack-*.idx do git show-index < $p | cut -f 2 -d ' ' done fi # And now find all loose objects: find .git/objects/ | egrep '[0-9a-f]{38}$' | \ sed -r 's,^.*([0-9a-f][0-9a-f])/([0-9a-f]{38}),\1\2,' 
  • If you on Linux/Mac: make it executable: chmod a+x all-objects.sh
  • Remember some small part of the missing data (string, method name, ...)
  • Find this part changing grep parameter in the following script

    for rev in $(./s.sh) ; do C=$(git show $rev | grep <METHOD_NAME_OR_SOMETHING_FROM_MISSING_FILE> ) if [[ "$C" != "" ]] ; then echo $rev echo $C fi done 
Sign up to request clarification or add additional context in comments.

1 Comment

Another useful trick: run git fsck and look for dangling blobs. If files were git added but never git commited, and then later removed from the index but not yet garbage-collected, they will be "dangling blobs".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.