Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop tracking a file without removing it from repo

Tags:

git

I have a config file which I want to keep on the remote repository, but I don't want to track its changes on my computer. Adding it to .gitignore doesn't do the trick.

The reason I don't want to track changes is because it's supposed to differ between computers depending on their environment.

like image 800
bgcode Avatar asked Aug 16 '11 00:08

bgcode


People also ask

How would you best force git to not track changes a file or directory?

What you probably want to do is this: git update-index --skip-worktree . (The third option, which you probably don't want is: git rm --cached .


2 Answers

If you want to temporarily stop tracking a file, you can still use

git update-index --assume-unchanged <file> // track changes again : git update-index --no-assume-unchanged <file> 
like image 182
theor Avatar answered Sep 28 '22 08:09

theor


If that's the case then you shouldn't have the file versioned at all; you should version a template of the file. For example, if the configuration file is foo/config.txt then you should have a versioned foo/config.txt.template in the repository with example (or blank) configuration settings. foo/config.txt should not be in the repository at all, and should be ignored with .gitignore.

Then, in a new clone, you just copy foo/config.txt.template to foo/config.txt and alter the settings as appropriate.

like image 36
cdhowie Avatar answered Sep 28 '22 08:09

cdhowie