Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Never Commit Changed Files (But still keep original revisioned.)

Tags:

git

perforce

What is a good git practice to denote that a changed file should never be committed?

For example, for a WordPress theme development project, I am tracking the original WordPress files in git; and the wp-config.php config file, which contains local info that only pertains to the current system, needs to be changed but I don't want to commit it to git.

In Perforce, I used to save this type of event as a numbered changelist and never check it in. I was wondering whether a similar trick is available with git.

like image 382
moey Avatar asked Dec 13 '11 06:12

moey


People also ask

Why is .gitignore not ignoring files?

gitignore list does not work to ignore files that are already committed into the Git repository. This means that if you: Make a commit to your Git repository, and then; Set up your .

How do I ignore unwanted changes in Git?

Creating an ignore file To avoid having to ignore unwanted files manually, you can create a . gitignore file in the working directory of your project. Inside this file, you can specify simple patterns that Git will use to determine whether or not a file should be ignored.

How do I turn off 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.


1 Answers

If you still want to keep wp-config.php versioned, but ignore any local change to it:

git update-index --assume-unchanged wp-config.php

This is different that a .gitignore, which would only work if you remove first wp-config.php from the index:

git rm --cache `wp-config.php`
echo wp-config.php >> .gitignore
like image 122
VonC Avatar answered Sep 26 '22 06:09

VonC