tags:

views:

45

answers:

1

Let's say I have a .noise file in the root of my repository. This file is frequently modified and committed to the remote repo by others on my team.

I want to completely ignore this file while I'm committing anything myself, but I still want to pull in the changes from the others, and I don't want to delete the file. If I use .git/info/exclude, then I have to git rm --cached the file so it doesn't show up in the repo.

Now doing that brings me from:

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .noise
#
# No changes added to commit (use "git add" and/or "git commit -a")

to:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    .noise
#

The 'Changes to be committed' scares me. I don't want to push the deletion of .noise back to the remote, I don't want it deleted on my filessytem either. I just don't want Git to see or have anything to do with it. I thought that git rm --cached was not supposed to stage any changes? Is that not so?

Any ideas?

+1  A: 

You can use:

$ git update-index --assume-unchanged -- .noise

update-index --assume-unchanged will make Git continue to track the file, but your changes won't be reflected in the index or added to the repo.

mipadi
As far as I understand, this way will work if the file will be unchanged actually. Git will fail to pull commits which modify this file somehow: "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." (See git-update-index(1))
Shcheklein
@Mipadi `git update-index --assume-unchanged` is something I tried a while ago. No effect!Adding the `-- .noise` seemed to do it. Now it is interesting because I thought update-index basically looped through the directory looking for changes again. I did not know it had to be called on individual files. Thanks.
Jonathan Dumaine
@Shcheklein "Git will fail to pull commits which modify this file somehow" Well maybe this isn't the end-all be-all solution then. I will have to test and verify if remote commits do get pulled down.
Jonathan Dumaine