Cleaning Git Repository: Rails Project, added Gems to Repo by mistake - ruby-on-rails

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.

Related

homebrew/core is a shallow clone in Fish shell

I tried to install something using brew install and this thing pops up
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
and when I copied that thing to make it run, this happens
fish: $(...) is not supported. In fish, please use '(brew)'.
git -C "$(brew --repo homebrew/core)" fetch --unshallow
^
What does it means and how can I fix these things? Is there's a workaround to ignore or fix?
Additional information about my workstation:
MacOS Mojave
Homebrew version 2.0.2
Does run brew doctor and it shows up as no problem
Using Fish shell (of course I do)
Update 1 :
It looks like I am an idiot leaving the $ there.
I did try to fix it with you guys suggestions, and this what happened.
Removing the $ from the command, like so
git -C "(brew --repo homebrew/core)" fetch --unshallow
and this happens
fatal: cannot change to '(brew --repo homebrew/core)': No such file or directory
Update 2 :
Also, #VonC asked me did brew --repo homebrew/core path exists by asking me to run these following line
brew --repo homebrew/core
and it comes up as this
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
which indicates that the repository path is still valid and ready to use
As mentioned in fish-shell/issue 1405
In bash, $(...) is equivalent to backticks, except it's supported inside a double-quoted string.
Fish does not use $(...) or backticks, it uses (...) instead
So:
git -C (brew --repo homebrew/core) fetch --unshallow
Issue 159 discusses the support of $() command substitution syntax.
Since 2012.
fatal: cannot change to '(brew --repo homebrew/core)': No such file or directory
Then double-check what brew --repo homebrew/core returns, and if the path exists.
As an alternative, seen here:
git -C $HOMEBREW_CORE fetch --unshallow
Using "" should be supported, as seen in "How to remove the shallow clone warning from HomeBrew", but not advisable, from glenn-jackman's comment.
Simplest explanation for a "shallow clone" is that it's simply a clone of the git repository without the revision history thereby reducing the git repo footprint. You can also specify "depth" to reduce the amount of revision history obtained from a git clone.
In your case, if you need the full history, a fetch --unshallow is needed.
Looks like I did a double oopsies.
Thanks to all comments to me that I am doing an oopsies. I appreciate it a lot.
Instead of typing
git -C "$(brew --repo homebrew/core)" fetch --unshallow
which fish does not really likes $ in that line,
use this instead :
git -C (brew --repo homebrew/core) fetch --unshallow
no $ and ".
AAAAND that's it.
Please comment if this does not help. I still doubt that really resolves this question or not lol

Github pulling does not work in - Rails 5

I'm trying to pull last commit that I made on github, and though I get no errors, I see no changes in the code. I messed up my schema file, but after I pull the code it does not change at all.
I searched here on stack and the solution that worked for others didn't work for me, and this is also my first time that I'm pulling code from github, so I could've probably done something wrong.
I used this code:
git fetch origin controller-generator
git git reset --hard FETCH_HEAD
This is what I get as the output
HEAD is now at 1fb8c97 Integrated friendly routes gem
'Integrated friendly routes gem' is my last commit that I want to pull, but nothing changes. I don't know if I need one more step or whatever it goes with it.
This is what I have in commit db file
And when I pull this, I get this
The last one should not be there.
This is output
equalsign:~/workspace/BlogAndPort/db/migrate (controller-generator) $ git reset --hard 1fb8c97d64f389904b3048fb2850fcfd8425cd36
HEAD is now at 1fb8c97 Integrated friendly routes gem
equalsign:~/workspace/BlogAndPort/db/migrate (controller-generator) $ git push -f origin HEAD
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
Everything up-to-date
The problem is still the same as shown in the pictures. db files did not change
If I understood, you are asking to reset your local/master with origin/master.
$ git fetch
$ git reset --hard origin/master
You can back (hard reset) to a commit that was working for you.
$ git reflog # copy the commit-sha where you want to back/reset
$ git reset --hard <commit-sha> # reset to the commit
Now, if all things are ok. Then Force (-f) Push to remote.
$ git push -f origin HEAD # update remote branch

Brew update failed: untracked working tree files would be overwritten by merge

Trying to update Homebrew with brew update I got the following error
error: The following untracked working tree files would be overwrittenby merge:
Library/Formula/argp-standalone.rb
Library/Formula/cocot.rb
Please move or remove them before you can merge.
Aborting
Updating e088818..5909e2c
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
I found a blog post by someone who experienced a similar problem after having installed Mountain Lion (which I did this week too). He explains how he removed the files referred to in the error message
I removed these files:
$ cd $(brew --prefix)
$ rm cocot.rb
However, removing these files didn't help with the brew update. Instead I had to manually update brew through git:
$ cd $(brew --prefix)
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.
Assuming those instructions are correct (which I maybe shouldn't assume), I tried to follow these instructions and do
$ cd $(brew --prefix)
$ rm cocot.rb
However, it said 'file doesn't exist' when I tried to rm cocot.rb
One thing I'm not sure about is the cd $(brew --prefix) Are those the exact words I type or do I have to replace prefix with something? the cd was successful, so I'm assuming it was correct -- it moved me into /usr/local, but there was no file to remove. Contents of /usr/local are
Cellar clamXav git mysql var Library doc heroku mysql-5.5.15-osx10.6-x86_64 README.md etc include rvm bin foreman lib share
At any rate, do you know how I can fix the 'brew update'
Update: After removing the files according to favoretti's instructions and trying chown -R <your_username> $(brew --prefix)/.git, I got the following error running brew update
error: The following untracked working tree files would be overwritten by merge:
Library/Aliases/gperftools
Library/Aliases/hashdeep
Library/Aliases/htop
Library/Aliases/nodejs
Library/Aliases/ocio
Library/Aliases/oiio
Library/Aliases/pgrep
Library/Aliases/pkill
Library/Aliases/qt4
Library/Aliases/twolame
Library/Aliases/wxwidgets
Library/Contributions/cmds/brew-aspell-dictionaries
Library/Contributions/cmds/brew-beer.rb
Library/Contributions/cmds/brew-dirty.rb
Library/Contributions/cmds/brew-graph
Library/Contributions/cmds/brew-grep
Library/Contributions/cmds/brew-leaves.rb
Library/Contributions/cmds/brew-linkapps.rb
Library/Contributions/cmds/brew-ls-taps.rb
Library/Contributions/cmds/brew-man
Library/Contributions/cmds/brew-md5-to-sha1
Library/Contributions/cmds/brew-mirror-check.rb
Library/Contributions/cmds/brew-pull.rb
Library/Contributions/cmds/brew-readall.rb
Library/Contributions/cmds/brew-server
Library/Contributions/cmds/brew-services.rb
Library/Contributions/cmds/brew-switch.rb
Library/Contributions/cmds/brew-test-bot.rb
Library/Contributions/cmds/brew-tests.rb
Library/Contributions/cmds/brew-unpack.rb
Library/Contributions/cmds/brew-which.rb
Library/Contributions/cmds/git
Library/Contributions/cmds/svn
Library/ENV/4.3/apr-1-config
Library/ENV/4.3/bsdmake
Library/ENV/4.3/c++
Library/ENV/4.3/c89
Library/ENV/4.3/c99
Library/ENV/4.3/cc
Library/ENV/4.3/clang
Library/ENV/4.3/clang++
Library/ENV/4.3/cpp
Library/ENV/4.3/g++
Library/ENV/4.3/gcc
Library/ENV/4.3/git
Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
Library/ENV/4.3/ld
Library/ENV/4.3/llvm-g++
Library/ENV/4.3/llvm-g++-4.2
Library/ENV/4.3/llvm-gcc
Library/ENV/4.3/llvm-gcc-4.2
Library/ENV/4.3/make
Library/ENV/4.3/mig
Library/ENV/4.3/sed
Library/ENV/4.3/svn
Library/ENV/4.3/xcrun
Library/ENV/libsuperenv.rb
Library/ENV/pkgconfig/leopard/libcrypto.pc
Library/ENV/pkgconfig/leopard/libcurl.pc
Library/ENV/pkgconfig/mountain_lion/libcurl.pc
Library/ENV/pkgconfig/mountain_lion/libexslt.pc
Library/ENV/pkgconfig/mountain_lion/libxml-2.0.pc
Library/ENV/pkgconfig/mountain_lion/libxslt.pc
Library/Formula/abcl.rb
Library/Formula/abcmidi.rb
Library/Formula/aiccu.rb
Library/Formula/akka.rb
Library/Formula/alac.rb
Library/Formula/alure.rb
Library/Formula/appledoc.rb
Library/Formula/arangodb.rb
Library/Formula/argp-standalone.rb
Library/Formula/argtable.rb
Library/Formula/autopano-sift-c.rb
Library/Formula/avian.rb
Library/Formula/avidemux.rb
Library/Formula/avro-cpp.rb
Library/Formula/aws-cloudsearch.rb
Library/Formula/aws-sns-cli.rb
Library/Formula/backupninja.rb
Library/Formula/bact.rb
Library/Formula/bam.rb
Library/Formula/basex.rb
Library/Formula/berkeley-db4.rb
Library/Formula/bind.rb
Library/Formula/blazeblogger.rb
Library/Formula/bochs.rb
Library/Formula/boost149.rb
Library/Formula/bsdconv.rb
Library/Formula/bsdmake.rb
Library/Formula/buildapp.rb
Library/Formula/bup.rb
Library/Formula/byacc.rb
Library/Formula/cadubi.rb
Library/Formula/camellia.rb
Library/Formula/casperjs.rb
Library/Formula/ccextractor.rb
Library/Formula/cconv.rb
Library/Formula/cdo.rb
Library/Formula/cdpr.rb
Library/Formula/cgvg.rb
Library/Formula/checkstyle.rb
Library/Formula/chordii.rb
Library/Formula/chruby.rb
Library/Formula/cifer.rb
Library/Formula/clhep.rb
Library/Formula/cntlm.rb
Library/Formula/cocot.rb
Library/Formula/cogl.rb
Library/Formula/collada-dom.rb
Library/Formula/crash.rb
Library/Formula/crossroads.rb
Library/Formula/crosstool-ng.rb
Library/Formula/css-crush.rb
Library/Formula/csync.rb
Library/Formula/ctemplate.rb
Library/Formula/curlftpfs.rb
Library/Formula/cutter.rb
Library/Formula/cvsutils.rb
Library/Formula/darkstat.rb
Library/Formula/darner.rb
Library/Formula/dart.rb
Library/Formula/dasm.rb
Library/Formula/debianutils.rb
Library/Formula/dfc.rb
Library/Formula/dgtal.rb
Library/Formula/dhcping.rb
Library/Formula/di.rb
Library/Formula/dmtx-utils.rb
Library/Formula/drip.rb
Library/Formula/dsniff.rb
Library/Fo
Aborting
Updating e088818..c1fbc29
Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
You need to do the following:
cd $(brew --prefix)
rm Library/Formula/argp-standalone.rb
rm Library/Formula/cocot.rb
And then do the
git fetch origin
git reset --hard origin/master
brew update
Basically, to explain a bit more:
cd $(brew --prefix)
tells cd to change the directory to whatever brew --prefix will output.
If you try executing brew --prefix command you should see something in lines of:
brew --prefix
/usr/local
So the command would be in this case an equivalent of cd /usr/local.
Newer brew versions have formulae under its installation prefix and Library/Formula/, so that's where you need to look for those outdated/changed files.
Note, that if you changed those formulae yourself for a particular reason (like pinning a version) this action will revert them back to default ones and may produce unwanted effects.
#TedPennings noted in comments that this worked for him, but his sequence was:
chown everything to my_username:admin, ie, sudo chown -R ted:admin $(brew --prefix)
run the two git commands above,git fetch origin and git reset --hard origin/master
cd $(brew --prefix)
git reset --hard HEAD
brew update
This is caused by an old bug in the update code that has long since been fixed. However, the nature of the bug requires that you do the following:
cd $(brew --repository)
git reset --hard FETCH_HEAD
If brew doctor still complains about uncommitted modifications, also run this command:
cd $(brew --repository)
git clean -fd
$ cd $(brew --prefix)
$ git clean -fd
$ git reset --hard
$ sudo chown -R `whoami` `brew --prefix`
$ brew update
Note: steps 2&3 worked for me since I did step 5 before 4 before I got the error. The brew update before changing the owner of the folder caused the whole problem.
I had a similar issue where my brew package library got downloaded as a root user and then I was not able to run brew update as git would complain about not able to merge the file.
Solution was to do :-
sudo chown -R <user> /usr/local/Library
Resetting the brew repository should be the most efficient way if you don't mind to discard potential modifications on formulas you might have been applied:
$ cd `brew --prefix`
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew update
I was able to fix this on my machine by adding admin group write (and setgid bit) permission at these paths:
sudo chmod -R g+ws /usr/local /Library/Caches/Homebrew
The s sets the group id on execution so that the write permissions aren't lost the next time a different admin user updates or upgrades Homebrew.
This answer is somewhat incomplete because when I try to do brew cleanup --force there is a permissions issue when Homebrew tries to remove content in /usr/local/Cellar/. (Unfortunately I'm not able to investigate this further at the moment.)
Another option is to just use git stash.
The brew update command performs a git pull, so if there are any changed files (or even file attributes, which happened to me when I changed permissions in the directory recursively) you have to somehow fix the conflicts. Using git stash is one way; it takes any changes and puts them aside so you effectively revert to the last updated repo version. The Homebrew 'location' is by default /usr/local and it installs as a git repository. You can look for a .git folder to see for yourself. I'm writing a homebrew uninstall script to be posted on my GitHub profile soon with more info.
sudo chown -R USER /usr/local/bin
note - for USER use command whom i.e. your username
sudo brew doctor
This approach may be simpler than some. It involves:
fixing a git issue so you can delegate management of changes to it again.
no manual moves of files or directories.
no manual adjustments of file or directory permissions.
Steps (with notes for those who want explanations):
cd $(brew --repository) // see Note 1 below
git remote add brew https://github.com/Homebrew/brew // see Note 2 below
git pull brew master // promising fast-forward report!
brew update // see Note 3 below
Overview:
From what I can tell, the actual cause of this issue is a change in the repo url. It's now brew and was brew.git. (Full up-to-date url: https://github.com/Homebrew/brew)
Note 1: This first command takes you from anywhere in your file structure to the correct directory. The directory structure is different for me than what others show above (Mac OS 10.11.16), but with this command, those differences should not matter.
Note 2: This second command adds the correct remote url to a new alias; I did so just in case this approach didn't accomplish what I wanted and I needed the previous address again. Since the new remote worked, I'll invite someone else to comment on simply changing the url aliased by origin. I'll happily update the answer to reflect what worked for you.
Note 3: This forth command has exactly the desired result: it reports a large number of updates, including the particularly nice report of "==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!" (emphasis theirs).
This post helped me after updating to El Capitan. In my case, chown wasn't working ("zsh: command not found: chown"), so step 1 was adding this line to my .zshrc:
export PATH="$PATH:/usr/sbin"
I'd already tried several of the more popular answers above, so I'm pretty sure that git status was coming up clean by the time I pasted in the critical command from the blog post:
sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
This should work.
1. cd `brew --prefix`
2. git fetch origin
3. git reset --hard origin/master
4. sudo brew update

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

Rails - removing folder from root

I accidentally unpacked a gem (paperclip) in my root folder. Now I can't get rid of it to save my life. I add it, remove, add it, stash it, try to check it out...nothing works. I know I'm not providing much detail, but has anyone run into this issue before? Rails env is 2.3.11.
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# paperclip-2.3.16/
nothing added to commit but untracked files present (use "git add" to track)
Try to do:
git rm -r --cached paperclip-2.3.16/*
You could also throw a -f on there before the --cached if you want, to try to force it.
I'm referring to this source:
http://www.kernel.org/pub/software/scm/git/docs/git-rm.html
Since is not tracked yet, you can just do a rm -rf paperclip-2.3.16 and it should remove it with no problems.

Resources