1

I am a new solo developer working on my first iOS app. I'm using Git for Mac to backup my progress and it's my first time using Git.

I'm developing the app across 2 laptops.

I also saved my Xcode project in my iCloud folder so that they would be synchronized across both macs.

Everything was working fine for the first 2 months, but I've come across this error on Git for Mac and I can no longer sync to Git nor revert to an older commit.

This is the error:

fatal: Reference has invalid format: 'refs/stash 2' (128)

My guess is that an iCloud synchronization error happened between my macs and that messed up Git.

All I would like to do is be able to fix git so that I can recover my last working commit and then I will remove my project from iCloud to prevent this error from happening again.

Any help you can provide would be greatly appreciated!

learning_swift
  • 107
  • 1
  • 5

1 Answers1

0

View the tree which is under your .git folder:
tree .git and check to see if you actually have this ref in your git filesystem.

If you want to reset your data (if you can) do git reset HEAD --hard it will reset your current branch to the latest commit.


Some other solutions you can try as well

Make a backup of your repository since the following commands are irreversible.

Search for the conflicted files and delete them
find . -type f -name "* conflicted copy*" -exec rm -f {} \;

lastly, remove any "conflicted" references from git's packed-refs file
awk '!/conflicted/' .git/packed-refs > temp && mv temp .git/packed-refs

Also take a look here (where the conflicts file may be in):

.git/logs/refs/remotes/origin/
.git/logs/refs/heads/
.git/refs/remotes/origin/
.git/refs/heads/

Hope it will help you fix the problem.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Thanks for the quick response @jsexpert! I opened Terminal on Mac and navigated to my Xcode project file and tried `tree .git` and got `-bash: tree: command not found`. I tried `git reset HEAD --hard` and got `Reference has invalid format: 'refs/stash 2'`. I am now looking into how to backup my repository before trying the other suggestions. Thanks. – learning_swift Feb 14 '15 at 19:53
  • In this case, git has identified the bad reference name already: it's `refs/stash 2` (with embedded space). This probably won't be "packed" so it will just be a file with that name: `.git/refs/stash 2`. Removing it should at worst lose one stash. What *else* might be lurking, I have no idea; I don't let icloud (or dropbox or anything like that) touch my .git directories.... – torek Feb 14 '15 at 19:56
  • Thanks @torek So should I type this into Terminal? `git rm .git/refs/stash 2 git commit -m "remove .git/refs/stash 2"` and yes-- I learned to never put my project files in a dropbox or iCloud folder from now on.. – learning_swift Feb 14 '15 at 20:03
  • Not `git rm`, just plain `rm`. Files inside the `.git` directory are git's internal state, asking git to do something with them is like trying to do your own appendectomy :-) – torek Feb 14 '15 at 20:06
  • Thanks for your help @torek & @jsexpert! I removed the conflicted file as described and am able to use Git again. I lost a bunch of progress from the last week, but at least I am not starting from scratch, so thanks! – learning_swift Feb 14 '15 at 20:29
  • Update: I found a commit where my latest changes were, so no progress was lost. Tried the project and it was good as before. All good! Thanks! – learning_swift Feb 14 '15 at 20:48
  • If you deleted only `.git/refs/stash 2` file, then you shouldn't have lost any saved history (unless there was corruption elsewhere) -- you can try `git fsck --lost-found` or examine reflogs to find possible positions of deleted refs. – Jakub Narębski Feb 14 '15 at 21:48