git 假设不变 vs 跳过工作树 - 忽略符号链接
我在 git 存储库和 Windows 方面遇到问题。问题是 git 存储库中有一个 Linux 符号链接,对于运行 Windows 的开发人员来说,这显然不起作用。现在,由于该符号链接永远不应该改变,我想找到一种方法来删除开发人员的符号链接,并在其位置添加一个文件夹(这就是符号所指向的),但让 git 忽略这些特定的更改。现在我可以删除符号链接,创建一个同名的文件夹,然后添加一个忽略所有内容的 .gitignore。现在,为了确保 git 忽略符号链接的删除,我在研究时发现了两种可能的解决方案。我找到的解决方案是:
git update-index --assume-unchanged [FILE]
git update-index --skip-worktree [FILE]
我的问题是哪个选项最有效?我想确保一旦我这样做了,除非我专门这样做,否则它永远不会被撤消。我想确保恢复、重置、创建分支、合并等......一切正常。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两种选择都有问题。每当索引被丢弃时(例如git重置),
--assume-unchanged
就会重置自己,所以这可能迟早会让你陷入困境。--skip-worktree
也是如此...但是,您可以维护一个不签出的本地文件列表,以便在必要时自动再次设置 Skip-worktree 位。步骤如下:core.sparseCheckout
设置为 true。.git/info/sparse-checkout
:*
包含所有内容,!/foo
排除符号链接 foo (/
表示锚定到顶层)。现在您可以继续,而不必担心 git 会自动提交目录,但请注意,如果有人在目录或其中的任何文件上显式运行
git add
,您仍然会遇到问题。[编辑添加:]经过进一步讨论,我们确定了最后一个问题的解决方案:在目录中放置一个带有
*
模式的 .gitignore 文件。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:core.sparseCheckout
to true for the repository..git/info/sparse-checkout
containing two patterns:*
to include everything and!/foo
to exclude the symlink foo (/
means anchor to top level).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.