Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep file in a Git repo, but don't track changes

Tags:

git

I have several files in a CodeIgniter site that I will want to have in the repo but not track any changes on.

For example, I deploy a new installation of this framework to a new client, I want the following files to be downloaded (they have default values CHANGEME) and I just have to make changes specific to this client (database credentials, email address info, custom CSS).

// the production config files i want the files but they need to be updated to specific client needs application/config/production/config.php application/config/production/database.php application/config/production/tank_auth.php // index page, defines the environment (production|development) /index.php // all of the css/js cache (keep the folder but not the contents) /assets/cache/* // production user based styling (color, fonts etc) needs to be updated specific to client needs /assets/frontend/css/user/frontend-user.css 

Currently if I run

git clone [email protected]:user123/myRepo.git httpdocs 

and then edit the files above, all is great. Until I release a hotfix or patch and run git pull. All of my changes are then overwritten.

like image 304
NDBoost Avatar asked Mar 20 '12 21:03

NDBoost


People also ask

How do I not track changes in git?

For files that aren't tracked by Git, you can use a . gitignore or exclude file. For files that are tracked by Git, you can tell Git to stop tracking them and to ignore changes.

How do I keep my git files untracked?

You have to add the untracked files of the repository by using the “git add” command and run the “git stash” command to save the untracked file and clean the current directory for working by removing the untracked file from the repository folder.


2 Answers

git has a different solution to do this. First change the file you do not want to be tracked and use the following command:

git update-index --assume-unchanged FILE_NAME 

and if you want to track the changes again use this command:

git update-index --no-assume-unchanged FILE_NAME 

git-update-index documentation

like image 130
nasirkhan Avatar answered Sep 23 '22 23:09

nasirkhan


To pull an answer out of the comments of another answer:

$ git update-index --skip-worktree FILENAME

Appears to be a better option than --assume-unchanged

More can be read about this here: Git - Difference Between 'assume-unchanged' and 'skip-worktree'

like image 20
Anthony Avatar answered Sep 25 '22 23:09

Anthony