git 假设不变 vs 跳过工作树 - 忽略符号链接

发布于 2024-11-09 17:17:09 字数 460 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

垂暮老矣 2024-11-16 17:17:09

两种选择都有问题。每当索引被丢弃时(例如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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文