Tell git never to update a file

I have a few files in git (namely configure files), that I need to be in the git repo, but I don’t want them to ever update (for some reason, running them, and make, changes the configure file).

So is there any way I can tell git to ignore any CHANGES to the file, but to keep the original file still in the repo? Currently the only way I’ve found out to do something like this is to add the file to the .gitignore file, and the git add the file to the project directly (using -f to override). Is there any better way?

  • How do I rewrite committer names in a git repository?
  • git reports - get changed files
  • Git and Bitbucket without SSH
  • Pipe git diff to git apply
  • How do I configure Jenkins to build all branches except a few which I exclude?
  • How to recover from “unordered stage entries in index” error in git
  • git-svn rejected Basic challenge now that VPN is required
  • Unexpected result in git-diff
  • View git diff from individual parents
  • Git revert deleted file and preserve file history
  • How can I use “git describe --match” sensibly in combination with a shallow clone?
  • Expand git's autocomplete feature to plumbing commands
  • 2 Solutions collect form web for “Tell git never to update a file”

    I wouldn’t manage those files with git at all. I’d put them in your .gitignore so git would ignore them, and put template files (such as foo.template for a file named foo, or maybe template/foo) into git. Then when you clone the repo, you can copy them out, and modify them, and git won’t do anything with the copies, while still managing the templates. If you have several such files, you can supply a script or make rule or something of the sort to populate all of your config files from their templates, to make it easier to get set up.

    A better design would be to separate project config from local config, or have project level defaults that can be overridden in a separate local file. The project level files get committed, the local files get ignored, and they are both used. Perhaps some config settings only make sense for the project and some only make sense locally, in which case you just pull the appropriate setting from the appropriate file; or you could use the project setting as defaults, and let the local config override the defaults. This way, you can update the project settings, which are shared, for everyone at once, while not interfering with people’s local settings. Of course, this depends on having control of the settings format; if you’re using a third-party tool that takes its settings in a particular format, all mixed into one file, you’ll probably have to use the template approach.

    You could use git update-index --assume-unchanged on the file.

    --assume-unchanged option can be used as a
    coarse file-level mechanism to ignore
    uncommitted changes in tracked files
    (akin to what .gitignore does for
    untracked files). You should remember
    that an explicit git add operation
    will still cause the file to be
    refreshed from the working tree. Git
    will fail (gracefully) in case it
    needs to modify this file in the index
    e.g. when merging in a commit; thus,
    in case the assumed-untracked file is
    changed upstream, you will need to
    handle the situation manually.

    Git Baby is a git and github fan, let's start git clone.