views:

74

answers:

1

Is there a way to tell git to ignore a file that's stored in its origin? Since the files in question are in the upstream repository, just adding them to .gitignore or .git/info/exclude don't work.

Background:

My upstream repository has some generated files in it. Every time I do a local rebuild, these generated files are changed and differ from the committed version. The generated files are in the repository because many users don't have the software to generate them (and I don't have the power to change this). These generated files are never generated by hand and I never want to commit them to my git repository. I have a separate mechanism to push them to the master repository (and I have no control over this separate mechanism).

I'm using a private git repository for making edits to an upstream subversion repository. To do this, I have a git repository just for pulling commits from subversion. That git repository is periodically synced via a cronjob. I then have private git repositories that are clones of the upstream git repository. I want git to not bug me about the generated files. I'm happy with either of these two results: the files are no longer tracked by my local git repository (but they should be tracked by the one that syncs with svn), or git will silently update my generated files but it will never commit my changes and the files will never show up in the "Changed but not updated:" section of "git status".

+2  A: 

git update-index --assume-unchanged may be your solution. Check the man page for more info.


  • --assume-unchanged

  • --no-assume-unchanged

When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

This option can be also 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.

Tordek