git assume unchanged vs skip worktree - ignoring a symbolic link
Asked Answered
C

1

27

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.

Compost answered 26/5, 2011 at 11:55 Comment(2)
possible duplicate of Git - Difference Between 'assume-unchanged' and 'skip-worktree'Demesne
@Demesne but this question is olderNameless
A
24

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.

Arborvitae answered 26/5, 2011 at 13:42 Comment(1)
By mistake i pressed SKIP WORK TREE and now I am not able to swich the local branch. What can I do to revert the action I have taken by mistake? Is there any option?Cornice

© 2022 - 2024 — McMap. All rights reserved.