Almost all projects that I've worked on have some kind of "frozen content" that should always come when cloned, yet rarely be changed (see below for an example). I've tried different approaches using git, but they're all error-prone: people frequently wind up accidentally committing changes.
It's a subtle case to be sure: the files/folders must be versioned, but the vast majority of changes shouldn't get pushed.
Looking around I have a couple options:
git update-index --assume-unchanged <file>
: Problem -- this would appear to be a local setting, so this only solves the problem on a given machine. New clones are prone to forget and still commit changes by accident.git update-index --skip-worktree <file>
: Problem -- Appears to have the same issue, since I don't think changes to the index are ever propogated.git rm --cached <file>
: Problem -- not really a solution at all since this toasts everyone's copy when pushed!echo <file> >> .gitignore
: Problem -- not really a solution, since this only controls whether an object is added to the repo.- use a smudge/clean filter to exclude file changes from commits (see jthill's answer): Problem -- complicated, error prone: still needs each developper to locally config.
An acceptable answer to this question doesn't require special actions by each new developer.
Why? Because this is precisely the problem with the above solutions, which, in my experience leads to situations where "somebody has committed that file again".
Searches easily turn up many questions. We need a final answer!
- How to freeze a file in a repository
- Prevent local changes getting pushed in Git
- git assume-unchanged implications
- Howto prevent git from pushing changes to some files
- Ignore modified (but not committed) files in git?
- Preventing a file overwrite with Git
Example:
Here's the case I'm dealing with ATM. My project is a website that embeds wiki software (which I did not write). The wiki component needs a non-trivial folder structure which is used rather like a database (should probably be one). It needs to find the folders and files already there to work. After awhile these files get big -- we don't want to track those changes! This folder structure also contains some config (I know). If I could include the bare copy in the repo, and somehow (almost) never track its changes, that would be perfect.