Git - “假设不变"和“跳过工作树"之间的区别 [英] Git - Difference Between 'assume-unchanged' and 'skip-worktree'
问题描述
我对我不想提交到我的存储库的文件进行了本地更改.它是用于在服务器上构建应用程序的配置文件,但我想使用不同的设置在本地构建.自然地,当我将git status"作为要上演的内容时,该文件总是会出现.我想隐藏此特定更改而不提交.我不会对该文件进行任何其他更改.
I have local changes to a file that I don't want to commit to my repository. It is a configuration file for building the application on a server, but I want to build locally with different settings. Naturally, the file always shows up when i do 'git status' as something to be staged. I would like to hide this particular change and not commit it. I won't make any other changes to the file.
经过一番挖掘,我看到了 2 个选项:假设不变"和跳过工作树".上一个问题 here 讨论了它们,但并没有真正解释它们的区别.我的问题是:这两个命令有何不同?为什么有人会使用其中一种?
After some digging around, I see 2 options: 'assume-unchanged' and 'skip-worktree'. A previous question here talks about them but doesn't really explain their differences. My question is this: how are the two commands different? Why would someone use one or the other?
推荐答案
你想要skip-worktree
.
assume-unchanged
是为检查一组文件是否被修改而代价高昂的情况而设计的;当您设置该位时,git
(当然)假定与索引的该部分相对应的文件在工作副本中没有被修改.所以它避免了 stat
调用的混乱.每当文件在索引中的条目发生更改时(因此,当文件在上游发生更改时),该位就会丢失.
assume-unchanged
is designed for cases where it is expensive to check whether a group of files have been modified; when you set the bit, git
(of course) assumes the files corresponding to that portion of the index have not been modified in the working copy. So it avoids a mess of stat
calls. This bit is lost whenever the file's entry in the index changes (so, when the file is changed upstream).
skip-worktree
不仅如此:即使 git
知道 文件已被修改(或需要由reset --hard
等),它会假装它没有,而是使用索引中的版本.这一直持续到索引被丢弃.
skip-worktree
is more than that: even where git
knows that the file has been modified (or needs to be modified by a reset --hard
or the like), it will pretend it has not been, using the version from the index instead. This persists until the index is discarded.
此处对这种差异的后果和典型用例进行了很好的总结:http://fallgamer.livejournal.com/93321.html .
There is a good summary of the ramifications of this difference and the typical use cases here: http://fallengamer.livejournal.com/93321.html .
来自那篇文章:
--assume-unchanged
假定开发人员不应更改文件.此标志旨在提高性能,用于不更改 SDK 等文件夹.--skip-worktree
在您指示 git 不要因为开发人员应该更改它而触及特定文件时很有用.例如,如果主存储库上游托管一些生产就绪的配置文件,并且您不想意外地提交对这些文件的更改,则--skip-worktree
正是你想要什么.
--assume-unchanged
assumes that a developer shouldn’t change a file. This flag is meant for improving performance for not-changing folders like SDKs.--skip-worktree
is useful when you instruct git not to touch a specific file ever because developers should change it. For example, if the main repository upstream hosts some production-ready configuration files and you don’t want to accidentally commit changes to those files,--skip-worktree
is exactly what you want.
这篇关于Git - “假设不变"和“跳过工作树"之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!