Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who touched my git assume-unchanged bit?

Tags:

git

git-index

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?
like image 588
Yuval Adam Avatar asked Sep 13 '11 08:09

Yuval Adam


People also ask

How to see assume unchanged git?

In order to set "assume unchanged" bit, use --assume-unchanged option. To unset, use --no-assume-unchanged . To see which files have the "assume unchanged" bit set, use git ls-files -v (see git-ls-files[1]).

What does -- skip Worktree do?

--skip-worktree explained: This allows you to make changes to a file that you don't want to be pushed to upstream. Use this option as already shown above.

What command is used to take a change out of the index?

The DROP INDEX command is used to delete an index in a table.

What is index in git?

The Git index is a critical data structure in Git. It serves as the “staging area” between the files you have on your filesystem and your commit history. When you run git add , the files from your working directory are hashed and stored as objects in the index, leading them to be “staged changes”.


2 Answers

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

like image 191
Jan Hudec Avatar answered Oct 21 '22 08:10

Jan Hudec


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.

like image 33
davidneedham Avatar answered Oct 21 '22 08:10

davidneedham