git假定不变,而不跳过工作树 - 忽略符号链接 [英] git assume unchanged vs skip worktree - ignoring a symbolic link

查看:257
本文介绍了git假定不变,而不跳过工作树 - 忽略符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git仓库和windows的问题。问题是git仓库中有一个linux符号链接,并且运行windows的开发者显然不能工作。现在,因为这个符号链接永远不会改变,我想找到一种方法来删除开发人员,并在其位置添加一个文件夹(这是符号指向的内容),但让git忽略这些特定更改。现在我可以删除符号链接,创建一个相同名称的文件夹,并添加忽略所有内容的.gitignore。现在,只要确保git忽略删除符号链接,我在研究时发现了两种可能的解决方案。我找到的解决方案是:

pre $ g $ update-index --assume-unchanged [FILE]
git update-index --skip-worktree [文件]

我的问题是哪个选项最适合?我想确保一旦我做到这一点,除非我专门做到这一点,否则它永远不会被撤消。我想确保恢复,重置,创建分支,合并等等......一切正常。

解决方案

问题。 - 假设 - 不变每当索引被丢弃时(例如git reset),它都会自动重置,这样可能迟早会让你受到影响。同样适用于 - skip-worktree ...但是,您可以维护本地文件列表以便不检出,以便自动重新设置skip-worktree位在必要时。以下是步骤:


  • 为存储库设置 core.sparseCheckout 为true。

  • 创建一个包含两个模式的文件 .git / info / sparse-checkout * 包含所有内容并且!/ foo 排除符号链接foo( / 表示锚点到顶层)。

  • 现在,手动设置skip-worktree位,然后删除符号链接。


    现在你可以继续下去而不必担心git会自动提交目录,但是请注意,如果某人在目录或任何文件上显式运行 git add ,你仍然会遇到问题



    经过进一步讨论,我们确定了最后一个问题的解决方案:将.gitignore文件与 * 目录中的模式。


    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.

    解决方案

    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.

    这篇关于git假定不变,而不跳过工作树 - 忽略符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆