8

I finally made a great step by abandoning SVN for Git and loving it. It must be somewhere, but I can't really find on how to do this, gitosis friendly.

I have my repo 'site' stored on a remote machine. I push my working copy and pull this data on a production machine. One mayor difference though is 'one' file: database.yml, which will never change on the production machine.

Is it possible (and if so, how), when the data is pulled from the repo, to "ignore" only this file? I am doing this manually at this point, but some elegance would be most appreciated.

Thanks.

Shyam
  • 2,357
  • 8
  • 32
  • 44

5 Answers5

8

Yes, it is possible.

git update-index --skip-worktree FILENAME

or

git update-index --assume-unchanged FILENAME

where FILENAME would be config/database.yml for your case.

If you use the second command (assume-unchanged), the files will revert after git reset command.

Evgenii
  • 36,389
  • 27
  • 134
  • 170
6

If "database.yml" got added to your git repo before you specified it in the ignore file, I think you have to remove it:

git rm config/database.yml
git commit -a -m "Removed database.yml"

Then, add database.yml file in your project, will work fine.

Arun Kumar Kandasamy
  • 1,016
  • 2
  • 12
  • 24
  • 1
    You will most likely want to keep it local on your disk: `git rm --cached config/database.yml` – Chloe Dec 14 '15 at 20:24
5

My advice: don't even put it into git. Make a database.yml.skel or something like that, so that a user can model their own database.yml, with that in mind as a sample. However, in my opinion conf files do not belong in version control - exactly for the reason you mention.

Ignoring is very easy: in fact, there are several ways to do it. The correct for this one is .gitignore file; another one is .git/info/excludes. See this answer for details.

So, off the top of my head:

echo database.yml >> config/.gitignore
git add config/.gitignore
git commit
Community
  • 1
  • 1
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • 2
    or put config/database.yml in .gitignore – shingara May 18 '10 at 12:51
  • If anyone uses the code above and they already have a .gitignore, it'll be gone. I recommend using `>>` and only using `>` if the first fails. (Depending how your shell is configured, `>>` may work in both cases where you have the file and you don't.) So the first line would be `echo database.yml >> config/.gitignore` instead. – iconoclast Jul 30 '12 at 17:03
  • 1
    Also, this does you no good if the database.yml is already in the repo. See Evgeny's answer for details on how to handle that situation. (I haven't tested his approach: it's a bit different from mine, but you're basically removing the file from the repo so the .gitignore can be applied.) – iconoclast Jul 30 '12 at 17:08
  • @iconoclast: I never said anything about what to do if it's already in the repo, just that it shouldn't be. Evgeny's code is definitely not removing code from the repo, and has nothing to do with `.gitignore` (except slight similarity in functionality). And I assume everyone who uses `git` can also tell the difference between `>` and `>>`, and modify to suit the occasion (or use an editor instead to do the same thing). – Amadan Jul 31 '12 at 00:29
  • 1
    Yes, but it seems pretty clear that it is already in the repo, since he asks how to ignore it when he PULLS, not ignore it from the working directory. (Remember he's new to Git so you can't count on his terminology being standard.) He seems to want the file in the repo to not overwrite his production file. – iconoclast Jul 31 '12 at 13:21
  • If the file is already in Git, use `git rm --cached config/database.yml` to remove it from Git while keeping it local on disk. – Chloe Dec 14 '15 at 20:23
0

Removing the database.yml is not a good idea if the application is designed to be downloaded and installed by other users. If you have unsophisticated users installing your application, the removal of the file is kind of a dick move. Telling git to ignore the file after adding it with default values is the correct way in this case.

0

If you want to remove your system cache or from your local machine simply run following command.

git rm --cached config/database.yml 

If you want to remove from git then run following commands

git rm config/database.yml
git commit -a -m "Removed database.yml"
git push branch_name
Ali Hassan Mirza
  • 552
  • 11
  • 23