19

I have a certain file in my repo that I have set the assume unchanged bit on:

git update-index --assume-unchanged someFile.txt

Once in a while, after some work on the repo, that bit is unset and the file is automagically not assume-unchanged anymore.

Who's touching it? How can I make this permanent until I explicitly tell git to:

git update-index --no-assume-unchanged someFile.txt

What's going on here?


Edit: I'm using the assume-unchanged bit on configuration files that change locally, and should never ever be committed, not to mention pushed upstream. I don't want to see them in git status, nor anywhere else, unless I explicitly tell git I want to edit and commit one of them.


Edit: OK, I think I managed to reproduce the issue.

I committed the file from a different repo (which didn't have it as --assume-unchanged), pulled on my repo, and sure enough, the bit was reset.

So two questions arise:

  1. Is it possible to set this bit on the central authoritative repo so that it propagates to all repos?
  2. Is it possible to make this bit sticky, even after remote changes to it?
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
  • I think the feature has been contemplated on the git list at least once already (at least in the thread mentioned by Mark below). I don't think anybody stepped up to implement it though. – Jan Hudec Sep 13 '11 at 12:18
  • Found another relevant thread: http://thread.gmane.org/gmane.comp.version-control.git/146082 – Yuval Adam Sep 13 '11 at 12:39
  • There is no authoritative repo - see my similar question here: http://stackoverflow.com/questions/25123374/stop-tracking-a-file-in-git-without-having-it-deleted-either-locally-or-on-pul/25123571?noredirect=1# and this blog post for git assume unchanged vs skip worktree: fallengamer.livejournal.com/93321.html – Mr_and_Mrs_D Aug 06 '14 at 14:31

2 Answers2

3

IIRC if you ignore a versioned file, it will behave like that. You can ignore across all work trees from .gitignore or in particular work tree from .git/info/exclude (yes, it works, but is not intended way of doing things).

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • 1
    Ignoring a file of this type that's "precious" can be dangerous. git regards ignored files as disposable, and may overwrite them while moving between versions. (The ignore mechanism is intended for build products.) – Mark Longair Sep 13 '11 at 09:40
  • Ignoring is not the issue at hand. Ignoring is for unversioned files. I am talking about `--assume-unchanged`'ing for versioned files. – Yuval Adam Sep 13 '11 at 09:51
  • @Yuval: Actually no, not only. I am not sure whether it's by design, side-effect of add semantics in git or by accident, but if a versioned file matches ignore pattern, git sees the file, but ignores changes made to it. In other words behaves similarly to `--assume-unchanged`. – Jan Hudec Sep 13 '11 at 10:17
  • @Mark: Do you have any reference that actually says that git treats ignored files as disposable? I think it does not. – Jan Hudec Sep 13 '11 at 10:23
  • 1
    @Jan Hudec: sure, have a look at [this thread from the git mailing list](http://git.661346.n2.nabble.com/ignored-file-can-be-deleted-silently-td6333578.html) where Junio says: 'Most of the time, "ignored" is also the same as "can be safely discarded'. I should add that this was a nasty surprise for me when I found it out the hard way... – Mark Longair Sep 13 '11 at 10:25
  • @Jan, from the docs: "Note that all the gitignore files really concern only files that are not already tracked by git; in order to ignore uncommitted changes in already tracked files, please refer to the git update-index --assume-unchanged documentation." Even if what you are suggesting works, it is not by design, and goes against the official documentation. – Yuval Adam Sep 13 '11 at 10:25
  • 2
    Hm, I see. Crossing the answer out (and keeping so others don't have to repeat the mistake) – Jan Hudec Sep 13 '11 at 11:10
1

It seems that --skip-worktree + sparse checkout could allow this sort of behavior.

From git assume unchanged vs skip worktree - ignoring a symbolic link (with some contextual modifications):

  • Set core.sparseCheckout to true for the repository.
  • Create a file .git/info/sparse-checkout containing two patterns: * to include everything and !/path/to/someFile.txt to exclude local file 'someFile.txt'.
  • Now, manually set the skip-worktree bit to someFile.txt.

Now you can go on without having to fear that git will automatically commit the directory, but note that you will still run into problems if someone explicitly runs git add on the directory or any file in it.

Further research in the man page seems to indicate that --skip-worktree is more appropriate for the use case being asked about.

Community
  • 1
  • 1
davidneedham
  • 378
  • 2
  • 9