I managed to delete to following files with git clean in my rails app:
Removing .DS_Store
Removing .bundle/
Removing config/application.yml
Removing db/development.sqlite3
Removing log/development.log
Removing public/system/profiles/avatars/000/000/011/
Removing public/system/profiles/avatars/000/000/012/
Removing tmp/
Are there any chances of getting back these files somehow or being able to copy from somewhere else? (Git deletes files permanently, so trash is empty. I also tried w/ disk drill but id didn't work out either.)
How can I protect my gitignored files properly to avoid these kinda situations in the future? Should I copy them sometimes or there are other programs to handle this?
Do I have to recreate my rails app or somebody knows a better option?
I think you can try to find these files in previous commits.
Next time remove using command git rm --cached file_name
I was able to pull it off. I ran bundle install (creates the files within .bundle) and reinstalled sqlite and figaro. After that I ran rake db:migrate which created the development.sqlite3 file. I lost the development data, but it is not a huge problem at all. For figaro I had to retype the keys and passwords (Sendgrid, Stripe, etc.) into the new application.yml file. Temporary and log files don't seem to be important. Thanks for the answers. This $git clean is pretty dangerous, watch out!
Related
I ran into a merge conflict in file db/development.sqlite3.
warning: Cannot merge binary files: db/development.sqlite3 (HEAD vs. nest-questions)
Auto-merging db/development.sqlite3
CONFLICT (content): Merge conflict in db/development.sqlite3
Normally I would open file (in Cloud9 IDE), manually edit out the conflict, and done.
But I cannot read anything in this file - it just looks like gibberish.
The app is in development. Can i just wipe out the file, then run rake db:reset, or will cause issues? I've never manually modified this file before.
Has anyone resolved a conflict in db/development.sqlite3 before and can advise?
You won't be able to resolve a merge of db/development.sqlite3 by hand. It's a binary format of the SQLite database that Rails is using behind the scenes when you are using rails console, rails server or an equivalent app server.
The typical approach is to make sure that these .sqlite3 files are ignored by git (since you don't usually wish to persist your database to your source code repository).
To resolve:
git rm db/*.sqlite3
git commit -m "Removing SQLite files from git"
rm .gitignore
wget https://raw.githubusercontent.com/github/gitignore/master/Rails.gitignore
mv Rails.gitignore .gitignore
git add .gitignore
git commit -m "Ignoring files that Rails recommends"
The sqlite files and many others will be ignored by this technique. Note that if the files in question are already in your repository, you'll be prompted to work with them as usual. You'll need to remove them from the repo using git rm before these changes take effect.
You can wipe out the file with db:reset, etc. as you mention above, but the problem will recur until you take the above (or similar) steps.
I'm using the cloud9 IDE with Ruby on Rails and having an issue with git.
I have a folder in my workspace called .c9 which contains all the cloud9 related files including it's regularly changing metadata.
I've added an ignore to my gitignore but keeps pushing to my bitbucket repository anyway. Worse when I branch off the metadata contained within goes out of sync and git insist i have to resolve the issue before I merge back.
I have no idea what I'm doing wrong here.
My gitignore looks like this:
# Ignore the c9 files.
/.c9
I have also tried
.c9, /.c9/*, .c9/* but no joy...
I've checked to see that it is actually in my workspace with la returning:
.c9/
.gitignore
Gemfile.lock
README.md
Todo.md
bin/
config.ru
lib/
public/
test/
vendor
.git/
Gemfile
Guardfile
Rakefile
app/
config/
db/
log/
spec/
tmp/
Any thoughts on where I'm going wrong?
I can confirm as per Jubobs comment above my solution in this case was resolved by running:
git rm --cached .c9/ -r
and then ensuring my gitignore featured the following lines
#Ignore all .c9 specific files<br>
/.c9/
I agree this is perhaps a duplicate of this question here: .DS_Store still appears in git status despite being in .gitignore
However as I went looking for a cloud9 specific answer perhaps this is still of use to some.
I'm getting a lot of untracked / modified files that are like this in my Rails app:
db/sphinx/development/user_core.spa
db/sphinx/development/user_core.spd
db/sphinx/development/book_core.sph
db/sphinx/development/book_core.spi
db/sphinx/development/book_core.spp
db/sphinx/development/book_core.sps
etc.
Should I include these when I commit and push in git, or should I put db/sphinx/development/* in my .gitignore file?
--EDIT after getting answer below--
I ended up adding this to my .gitignore file...
# Ignore certain Sphinx files
/db/sphinx/*
/config/*.sphinx.conf
...and then doing what is recommended here: Ignore files that have already been committed to a Git repository
You should add those to .gitignore. They're similar to database files. The only sphinx specific file I think you might want to check in is the config/sphinx.yml files, assuming it doesn't contain any sensitive information.
I have 2 versions of the same migration (bad habit, I know). I deleted old version many times, but after restarting my project (or do something with it, like rake db:test:prepare), the file shows up in my migrate folder. When I run rake db:migrate, it will complain about multiple migrations with the same name.
How can I delete a migration file completely? Is there a registry that I need to remove to prevent it from coming back?
Are you updating from a repo? I don't see how the original file could be restored otherwise.
You can also delete the entry from the schema_migration table, but that just tracks if it's been run or not (IIRC).
git add only adds new and changed files, it doesn't remove deleted ones. To delete:
git rm db/migrate/<filename>
or if you have already deleted it from the filesystem:
git add -u
I have a rails 3 application in local. I created reposority and i know the basics of git like git. I am using git for heroku but i haven't push my application to public place before. What i want to learn is :
Which files should i add to git ignore? Because i have some personal passwords and keys in environments.rb and also have some keys in initializers.
If i add some files in git ignore, i guess it will be a problem for people who clones it, because some files will be missing.
I will also keep on working on my application, i can always add new keys to environment.rb or somewhere else. Do i have to clone(branch) my application? I heard something "branch, master" but i have no idea about these terms?
The idea of gitignore is that often there are temporary files, or files that are specific to your IDE. They add nothing to source code, and sometimes they contain sensible information about your machine that you probably don't want to share.
This repo on github is a nice collection of gitignore templates:
https://github.com/github/gitignore
Rails template is available: https://github.com/github/gitignore/blob/master/Rails.gitignore
EDIT
If you have files with you current configuration, which are important for your app, remove all the sensitive information from them, check them in, and after that modify gitignore file.
If you have already checked in a file with passwords, use this manual: http://help.github.com/removing-sensitive-data/
Create a .gitignore file in your root directory, and add all the files which you do not want to track. Make sure those files are not already tracked. If they are, delete the files, commit the change to the git repository, and then add those files to your .gitignore file.
Your .gitignore file could look something like this
log
db/*.sqlite3
db/*.sql
*.tmproj
tmp
coverage
config/database.yml
*~
\#*\#
.\#*
target/*
**/.DS_Store
.DS_Store