Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git assume unchanged vs skip worktree - ignoring a symbolic link

Tags:

I have a problems with a git repository and windows. The problem is that the git repository has a linux symbolic link in it and with developers running windows, that obviously does not work. Now since that symbolic link should never change, I want to find a way to delete that on developers and add a folder in its place (which is what the symbolic points to) but have git ignore those particular changes. Now I can remove the symbolic links, create a folder of the same name and just add a .gitignore that ignores everything. Now as far as making sure git ignore the removal of the symbolic link, I have found two possible solution while researching. The solutions I found are:

git update-index --assume-unchanged [FILE] git update-index --skip-worktree [FILE] 

My question is which option would work the best? I want to make sure once I do this that it never gets undone unless I specifically do it. I want to make sure reverting, resetting, creating branches, merging, etc... all work fine.

like image 236
ryanzec Avatar asked May 26 '11 11:05

ryanzec


People also ask

What is git assume unchanged?

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git.

What is refresh index in git?

git/index changed by Windows. So it can only refresh the index and replace the . git/index file, which makes the next git status super fast and git status in Windows very slow (because the Windows system will refresh the index file again).

Does assume-unchanged and Skip-worktree work in Git?

Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked. This does not work as expected, since Git may still check working tree files against the index when performing certain operations.

How do I ignore changes to a tracked file in Git?

In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended. For example, if the file you want to change is some sort of config file, the repository can include a sample config file that can then be copied into the ignored name and modified.

How do I make changes to a working tree file in Git?

When you make changes to working tree files, you have to explicitly tell Git about it by dropping "assume unchanged" bit, either before or after you modify them. In order to set "assume unchanged" bit, use --assume-unchanged option. To unset, use --no-assume-unchanged.

What happens when you make a change to a Git file incognito?

It won’t show up on your git status anymore. If a change is made to the file, it will again be flagged with an unmerged or needs updating state. To make the incognito status more permanent, just add the skip-worktree flag like so:


1 Answers

Both options have problems. --assume-unchanged resets itself whenever the index gets discarded (e.g. git reset), so that will probably trip you up sooner or later. Same goes for --skip-worktree... however, you can maintain a local list of files to not check out, so that the skip-worktree bit is set again automatically whenever necessary. Here are the steps:

  • Set core.sparseCheckout to true for the repository.
  • Create a file .git/info/sparse-checkout containing two patterns: * to include everything and !/foo to exclude the symlink foo (/ means anchor to top level).
  • Now, manually set the skip-worktree bit, then delete the symlink.

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.

[Edited to add:] After further discussion, we identified a solution to that last problem: put a .gitignore file with a * pattern inside the directory.

like image 55
Jan Krüger Avatar answered Sep 20 '22 12:09

Jan Krüger