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

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!

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.

Related

How do I remove the .exec extension git applies to files?

I messed up so I downloaded an old commit and tried to build from some old code that functioned as intended. I see the files (Podfile, License Gemfile etc) now have a .exec extension and when I push to bitBucket they have a "+x" annotation. When you hover over it says this file is now executable.
Everything still happens to build and run successfully but why does git add this extension to my files without my say so? This issue is causing some concern on my pull request. How do I return my files to being just plainText or whatever they were originally?
I've tried to run chmod -x $(find . -type exec) in the offending directory but this doesn't seem to work.
Anyone know how restore my file to their former purity???
You could:
rename your files
add them again, explicitely removing the 'x' executable bit with git add --chmod=-x aFile
Then you can commit and push again.
But make sure to use Git 2.31 (Q1 2021), because of various fixes on "git add --chmod"(man)".
See commit 9ebd7fe, commit 4896089, commit c937d70 (22 Feb 2021) by Matheus Tavares (matheustavares).
(Merged by Junio C Hamano -- gitster -- in commit f277234, 25 Feb 2021)
add: propagate --chmod errors to exit status
Signed-off-by: Matheus Tavares
Reviewed-by: Taylor Blau
If add encounters an error while applying the --chmod changes, it prints a message to stderr, but exits with a success code.
This might have been an oversight, as the command does exit with a non-zero code in other situations where it cannot (or refuses to) update all of the requested paths (e.g. when some of the given paths are ignored).
So make the exit behavior more consistent by also propagating --chmod errors to the exit status.
And:
add --chmod: don't update index when --dry-run is used
Helped-by: Junio C Hamano
Signed-off-by: Matheus Tavares
Reviewed-by: Taylor Blau
git add --chmod(man) applies the mode changes even when --dry-run is used.
Fix that and add some tests for this option combination.

why does git recommits all files even the ones that I did not change

I am contributing to a project and forked their repository.
I have spent a few days on coding some new features and when I commit my changes to github every single fine gets recommited.... Even if I have not changed the file..
Why is this happening, I am new to vagrant and git.
My workflow is the following:
cd into the project:
/rails_projects/my_project
vagrant up
vagrant ssh
cd /vagrant
*****do some changes here to my code
git add .
git commit -m "asdfsdf"
git push
Is there something I missed with vagrant or git? I am on Windows running the suggested ubuntu virtual box. Maybe I had to create the virtual box in the parent directory instead of in the directory of my project? Or what is the deal? Or am i supposed to run the git commands from a different directory?
Thanks
So what ended up happening was that I had to do
cd ..
To get out of /vagrant file and then also
exit
To get out of vagrant ssh session.
Then I committed to github and everything was fine. Thanks!
To clarify for others.
It looks like you were trying to commit code from within your Vagrant box. As the OP has already found out, you don't want to do this (as the local Git repository is located on your computer, not inside the virtual machine Vagrant manages for you).
Personally, I have a terminal window open for Git and another open for Vagrant. This prevents the issue described in this question.
Bonus tip: If you develop using a Mac, you can hit Command + T whilst in Terminal to open a new tab. It's a shame you can't do this on Windows....

Cleaning Git Repository: Rails Project, added Gems to Repo by mistake

I was trying to solve an issue with some gem conflicts, and I added all of my gems to vendor/cache, I have since removed them, but now I have a 40M pack file where it used to be less than 1M.
I have tried to filter the branch
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch vendor/cache' --prune-empty -- --all
This goes through a list of rm commands, for example:
rm 'vendor/cache/sass-3.2.8.gem'
and then at the end
Rewrite 9c90286ba515f46919e82e73e2c01a5db1762668 (202/202)
Ref 'refs/heads/master' was rewritten
Ref 'refs/remotes/origin/master' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged
Finally I run
git gc --aggressive --expire=now
But I still have the same huge number of objects, and the pack file is still 40M. I even try forcing a push when this was complete with no change. Any idea how I can clean up my repository following this mistake?
I think you'll find the answer at the bottom of the question or in the accepted answer here:
Remove file from git repository (history)
The key is in that warning line you have:
WARNING: Ref 'refs/remotes/origin/master' is unchanged
The solution discusses how to get rid of that so that the other steps accomplish what you want and reduce the size back down.

How to completely ignore directories that until now I was tracking under version control using git?

I am using Ruby on Rails, the Capistrano gem and git. I would like to do not put anymore under version control some directories that until now I was tracking.
For my application I have a file system structure like the following:
...
.gitignore
/public/aaa/000/001
/public/aaa/000/002
/public/aaa/000/003
/public/aaa/000/...
To accomplish that I aim, I changed the .gitignore file and added to it the following lines:
# Ignoring "/public/aaa/*" directories
public/aaa/
However, if I check what directories are under version control, I see that those I would like to ignore are still tracked. So, when I deploy with Capistrano to the remote server the content of those directories is still changing.
How can I definitely ignore those directories?
In few words, what I would like to do is to do not change public/aaa directories and files on the remote machine (and, thus, to do not track those with git on my local machine) so that when I deploy with Capistrano those folders (on the remote machine) are untouched.
You'll need to remove them before they'll disappear from source control. They're still part of your git repo, so git is going to continue paying attention to them.
git rm -r --cached public/aaa
The -r tells git to remove the directory (just like rm -r in the console) and --cached tells git to leave the file(s), just remove it from the repo.
You could use git update-index --assume-unchanged <filename>. This will keep the files around, but will no longer track their changes.
You can do this recursively with
find ./folder/ -type f | xargs git update-index --assume-unchanged

pushing to heroku git error

I have created a brand new heroku app, beforehand i deleted the old .git file from my app's directory and created a new one with the usual steps:
git init, git add ., git commit -m "new git"
all of which worked fine. I then created a new app like so and got the following error:
$ heroku create
Creating glowing-summer-56.... done
Created http://glowing-summer-56.heroku.com/ | git#heroku.com:glowing-summer-56.
git
Git remote heroku added
$ git push heroku master
Counting objects: 1553, done.
Delta compression using up to 4 threads.
fatal: object 91f5d3ee9e2edcd42e961ed2eb254d5181cbc734 inconsistent object lengt
h (387 vs 8985)
error: pack-objects died with strange error
error: failed to push some refs to 'git#heroku.com:glowing-summer-56.git'
This is strange to me, as it is a brand new .git file. How can I get rid of this without cleaning up each damaged object? Is there a way to just delete the git file and start anew? I'm not using this git file for anything other than pushing to heroku.
Also I should note that I am using Cygwin on windows and my git version is 1.6.6.1
I've come across this error before and fixed it, I just honestly can't remember how.
Finally, using git fsck --full yields nothing :(
Thanks,
i seemingly fixed this with: git reset

Resources