Git - '假定 - 不变'和'skip-worktree'之间的区别 [英] Git - Difference Between 'assume-unchanged' and 'skip-worktree'

查看:685
本文介绍了Git - '假定 - 不变'和'skip-worktree'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我不想提交到我的存储库的文件进行本地更改。它是一个用于在服务器上构建应用程序的配置文件,但我想用不同的设置在本地构建。当然,当我把'git status'作为上演的东西的时候,这个文件总是显示出来。我想隐藏这个特定的变化,而不是提交它。我不会对文件做任何其他更改。



经过一番挖掘,我看到了两个选项:'assume-unchanged'和'skip-worktree'。以前的问题这里是关于它们的讨论,但并没有真正解释它们的区别。我的问题是这两个命令如何不同?为什么会有人使用其中之一?

解决方案

您需要 skip-worktree
$ b

假定 - 不变设计用于检查一组文件是否具有昂贵被修改;当你设置这个位时, git (当然)假定在该工作副本中没有修改对应于该索引部分的文件。所以它避免了 stat 调用的混乱。只要文件在索引中的条目发生更改(因此,文件在上游发生更改时),该位就会丢失。



skip-worktree 不止是这样:即使在 git 知道文件已被修改(或者需要被 reset --hard 之类的),它会假装它不是,使用索引中的版本代替。这一直持续到索引被丢弃为止。



有一个关于这种差异的分支和典型用例的很好的总结: http://fallengamer.livejournal.com/93321.html



从那篇文章:


  • - 假设 - 不变假设开发者不应更改文件。此标志旨在用于提高性能,以用于SDK等不可更改的文件夹。

  • - skip-worktree 在您指示git不触及特定文件时非常有用,因为开发者
  • 强>改变它。例如,如果主存储库上游托管了一些生产就绪的配置文件,并且您不想意外提交对这些文件的更改, - skip-worktree 正是你想要的。

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.

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?

解决方案

You want skip-worktree.

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

There is a good summary of the ramifications of this difference and the typical use cases here: http://fallengamer.livejournal.com/93321.html .

From that article:

  • --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 - '假定 - 不变'和'skip-worktree'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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