Who touched my git assume-unchanged bit?
Asked Answered
L

2

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?
Letreece answered 13/9, 2011 at 8:52 Comment(3)
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.Meganmeganthropus
Found another relevant thread: thread.gmane.org/gmane.comp.version-control.git/146082Letreece
There is no authoritative repo - see my similar question here: #25123874 and this blog post for git assume unchanged vs skip worktree: fallengamer.livejournal.com/93321.htmlWavy
M
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).

Meganmeganthropus answered 13/9, 2011 at 9:27 Comment(7)
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.)Telford
Ignoring is not the issue at hand. Ignoring is for unversioned files. I am talking about --assume-unchanged'ing for versioned files.Letreece
@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.Meganmeganthropus
@Mark: Do you have any reference that actually says that git treats ignored files as disposable? I think it does not.Meganmeganthropus
@Jan Hudec: sure, have a look at this thread from the git mailing list 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...Telford
@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.Letreece
Hm, I see. Crossing the answer out (and keeping so others don't have to repeat the mistake)Meganmeganthropus
A
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.

Almagest answered 11/9, 2013 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.