Question

I have a simple problem with my git :

I have this file inc.conf.php on my repository on github. I don"t want to delete him from the repo, it's a basic config file.

Now, on my local repo, I have the same file inc.cong.php with my own config, and I don"t want this file will be commited.

So I create a .gitignore and I add inc.config.php in. (the .gitignore is commit and push on the repo)

But when I update the file inc.config.php in local and tape git status :

On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Swindle-Foundation5/inc.config.php

no changes added to commit (use "git add" and/or "git commit -a")

But I don"t want to change the file on the repository from github. How can I do this ?

Was it helpful?

Solution 2

.gitignore tells which files you don't want in the repository. If you do put a file in the repository, then git is going to track it. It's quite contradictory to tell git I don't want to track this file (via .gitignore), but I also want to track this file (by adding it to the repository).

There are ways to make git not commit changes to that file on every commit, which is tedious and ugly. My suggestion is to work this out in your head first. Do you or do you not want to track the file? If you do, then all changes to the file will be tracked too.

One option you have is to generate the file via a bootstrap. For example:

# make a backup of the file
$ git mv Swindle-Foundation5/inc.config.php Swindle-Foundation5/inc.config.php-template
# add the file to .gitignore
$ echo "inc.config.php" >> .gitignore
# commit
$ git commit -a

So you basically keep track of a copy of the file, not the file itself. And add a script that generates that file (e.g. bootstrap.bash):

#! /bin/bash

cp Swindle-Foundation5/inc.config.php-template Swindle-Foundation5/inc.config.php

This way, you can update the template in the future, you can also keep it in the repository, but every time you change your actual configuration, they would not be tracked because they belong to a file that is being ignored and is not in the repository.

OTHER TIPS

.gitignore is only meant to prevent files from being tracked. Once a file is tracked, the ignore file has no effect on it.

You can make Git ignore changes to your file using git update-index --assume-unchanged Swindle-Foundation5/inc.config.php.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top