Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: ignoring a file which *is* version controlled

Tags:

git

A .gitignore file allows to ignore files from version controlling them at all.

We have a different situation: we want to place in the repository some configuration files, that need to be changed on per-machine basis (db access info for instance).

We do want to distribute them, as placeholders, so we include them into the repository. However, later we want any changes to them to be ignored, for all developers.

Is there a way to do it?

Note:

The question Git: Ignoring Version-Controlled Files is actually the same. However, none of the answers answered the question, including the accepted one.

Edit:

  • Is there a way to do --assume-unchanged to a pattern rather than a single file?
  • Is there a way to propagate this command to the repositories of other developers?
like image 599
shealtiel Avatar asked Feb 16 '11 00:02

shealtiel


People also ask

How do I ignore certain files in git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

What is the purpose of a git ignore file?

When Do You Use Git Ignore File? The git ignore file rule allows you to ignore a file you've committed in the past. You use it when you do not want to recommit a file, for example a build artifact.

How do I stop git from ignoring files?

If you already git add ed some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use git rm --cached on them. git rm --cached file_name. ext wroks fine for me to update gitignore for one file.

How do you see which files git is ignoring?

Git Ignoring Files and Folders Checking if a file is ignored From Git 1.7. 6 onwards you can also use git status --ignored in order to see ignored files. You can find more info on this in the official documentation or in Finding files ignored by .


2 Answers

I define the following aliases in my .gitconfig file:

[alias]
  ignore = update-index --assume-unchanged
  unignore = update-index --no-assume-unchanged

That should do exactly what you want: running git ignore some-file will treat the file as unchanged no matter what you do to it, until you run git unignore some-file.

like image 162
Adrian Petrescu Avatar answered Sep 20 '22 22:09

Adrian Petrescu


I know this kind of dodges the issue, but I would have a ".defaults" file for each, and then change this. This helps with the configuration energy anyway - what if someone who has a custom configuration wants to change the defaults?

Don't ignore the .defaults, ignore the actual thing. Maybe have a script that copies the .defaults to the regular ones if they don't already exist.

like image 34
alternative Avatar answered Sep 16 '22 22:09

alternative