Search code examples
iosmacosgitsynchronizationicloud

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


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!


Solution

  • 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.