git push heroku - stop heroku pushing/uploading massive file - ruby-on-rails

Having accidentally put a pretty large file which was not excluded by .gitignore in my working directory i committed my changes, pushed up to github then did a git push heroku up to production.
when i saw it was trying to push 100s of MB of data up to heroku, i killed the process.
I have since done a
git rm filename.extension
followed by
git add ., a new commit and git push. But when i get to git push heroku it insists on continuing to push this impossibly large data file.
how can i check what the offending file is, and how can i make git/heroku forget it was ever there so git push heroku can start working again...?
Thanks!

If you did a git rm large.file, the commit introducing the large.file is still in the history of your repo.
To make git forget about the commit, you'll need to remove it from your repo's history. This could be done using git rebase as described in the answers to these questions (for example):
How do you remove a specific revision in the git history?
How to remove selected commit log entries from a Git repository while keeping their changes?
After you removed the commit from the history, you could git push -f github and then git push -f heroku.
Note that git push -f could cause problems if someone fetched the state of your github repo since your last push. See chapter The Perils of Rebasing in the progit book for an explanation why.

Related

Git merge conflict with workspace.xml

I'm trying to push my Rails project to Heroku, but Git isn't allowing me to do anything at the moment. Here's what I've done so far:
git push heroku failed because the heroku branch was "ahead" of my local branch, which should not have been possible.
I pulled and there was a conflict with .idea/workspace.xml. I wasn't able to find out what that file is, but it's huge and Git wrote all kinds of garble to it. Too much to manually "resolve" conflicts.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
I ran git add -A (also tried git add . and git add)
git commit --amend fails because "You are in the middle of a merge"
git merge --abort fails because "Untracked working tree file '.idea/workspace.xml' would be overwritten by merge (despite the fact that the file has been moved)
git reset --merge fails for the same reason.
How can I make Git work again?
.idea/workspace.xml
This file is your idea workspace files. They are generated by IntelliJ tools.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
Simply add the folder to your .gitignore but since its already committed you will have to remove it from the repository:
# Quit the merge
git merge --abort
# remove the whole folder from the repo
git rm -rf --cached .idea/
# add it to the .gitignore: idea/
# add and commit your changes
git add .- A
git commit -m " Removed idea folder"
git push origin <branch>
If you still unable to do it?
First reset the code to the previous state and then do the above code again.
The reset will take you to your last commit before the pull
git commit -am "message" worked (as opposed to amending a commit)
I have resolved a similar problem by simply deleting the workspace.xml file. By building and running the program again idea will autogenerate a compatible file.

Rails filing system's don't match

When I built my Rails environment my file system in my IDE and on Bitbucket got mitched-matched. How should I fix it?
You might want to try doing a git pull ... as suggested by the error/hint message in your screenshot.
If that fails, then try git pull --rebase to rebase your code onto the HEAD
Also, try git push -f.
Note: A forced push overwrites the structure and sequence of commits on the authoritative repository, throwing away other people's commits. git push -f should be avoided.

Rollback everything

I will be making changes to a production app soon and I would like to know how to rollback all changes to the database and code. I think with pgbackups and if needed heroku db:push and pull that will rollback the database, but what about the code? Is there a way using git that this could be done, or maybe just to copy the whole folder and copy it back in if there are errors and upload everything again?
Thanks.
For managing your code, use git tags.
Find the commit of the code currently in production and tag it.
Add a new tag to the HEAD commit you intend to push to production
If the code needs to be rolled back, you can target the older tag during your push to heroku.
You can run git log to see the history of commits. Find the commit made just prior to your last push to production. Find the hash for that commit (on the same line as the git message in the log) and tag it
git tag -a v0.1 THEHASH
Now tag your HEAD
git tag -a v0.2
Now push to heroku
git push -f heroku v0.2^{}:master
If things go bad, rollback to v.0.1
git push -f heroku v0.1^{}:master
You can do the pure git workflow, however heroku does support releases.
heroku releases will list all your releases. heroku releases:rollback v1 will create a new release containing exactly your slug as of the v1 release.
Neither this nor the git based rollback would make any changes to your data, so if there were data migrations run they'd have to be manually rolled back as well.

Can I delete my local .git repo?

My heroku repo grew to 1.5gb, so the nice fellows at heroku support cleared out the remote heroku repo and suggested I push a fresh copy.
However, the results of du -h .git locally show .git to be 276m. And, predictably, heroku throws an error when I try to push master to it.
So, my question: can I delete my local .git folder, do git init and push to heroku? What exactly would that do?
My app's code is pushed to github - my usual workflow is:
git add .
git commit -m "message"
git push #to github
git push heroku master
Possible Problems
There are two likely reasons your repository could be larger than expected.
You have a lot of binary assets in your repository.
You have a huge commit history.
Possible Solutions
If either of these things are the cause, you have a few options. Consider the following.
If your problem is binary assets, move your assets to an external asset store (e.g. Amazon S3 or a remote filesystem). You can then remove them from your history with git-filter-branch followed by git-gc. This will slim down your repository a lot.
If your problem is a really large history, make a separate shallow clone to push to Heroku. For example:
git clone --depth 1 my_repo heroku_repo
Well, you couldn't do that, unless you force a push (which is almost never recommended). This would erase your whole commit history and create a brand new repository.
But if you WANT to erase everything because of space... you can. It's just... strange.
What happens if you only push master?
You might want to do some housekeeping.
Do the upvoted answer but bear in mind that you can't push a shallow clone. Here's a follow up: Pushing to github after a shallow clone

Heroku -- Push new content to a heroku app created from a different machine

Our team is working on an app. We have a SVN based app. We also pushed the app to heroku. The other day the app was pushed by one member of the team, and after a couple of days of work and making some updations other member wants to push his data on heroku in the same repo from another machine. How can this be done?
Please Help.
Thanks in Advance.
You need to use Git to push applications to Heroku. If your source control of choice is Subversion, then you can use git-svn to deal with a Subversion repository using Git, including pushing to Heroku.
You need to add a git remote to the Heroku Git URL. You can find this URL in your Heroku account at heroku.com.
# stuff about setting up git-svn
$ git remote add heroku #{heroku_git_url}
$ git push heroku master
As another commenter mentioned, you will also need to manage SSH keys. The user doing the pushing will need to have an SSH private key (you can look up ssh-keygen) and will need to have the SSH public key uploaded to Heroku (heroku ssh subcommand).
So if your app is deployed and you already have a working copy. And you need to push changes.
You only want the repo with no content.
git clone --no-checkout git#heroku.com:<your-app-name>
That will clone the repo into a directory named your-app-name, and in that directory will be the repo you want. Move that .git file next to your .svn file.
mv <your-app-name>/.git ~/Code/<your-working-copy>
rm -rf <you-app-name>
You can rename the origin remote to heroku if you want. Otherwise just
git commit -am "Deploying v1.2"
git push

Resources