4

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".

1 Answer 1

3

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.

2
  • Can you actually use that on a specific path ? Aug 15, 2011 at 13:50
  • i've tried it on my project and couldn't get it to delete the files on remote: git update-index --no-assume-unchanged MyProject.xcodeproj/project.xcworkspace/xcuserdata/ Aug 15, 2011 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.