当与git clone [path]一起使用时, - local实际上做了什么吗?

时间:2017-07-25 03:10:31

标签: git

根据git help clone的输出,--local选项执行以下操作:

   --local, -l
       When the repository to clone from is on a local machine, this flag bypasses the normal "Git
       aware" transport mechanism and clones the repository by making a copy of HEAD and everything
       under objects and refs directories. The files under .git/objects/ directory are hardlinked to
       save space when possible.

       If the repository is specified as a local path (e.g., /path/to/repo), this is the default, and
       --local is essentially a no-op. If the repository is specified as a URL, then this flag is
       ignored (and we never use the local optimizations). Specifying --no-local will override the
       default when /path/to/repo is given, using the regular Git transport instead.

如果我正确读取此内容,则第二段说明只要给出本地路径,此选项将默认为on,并且只要给定路径不是本地路径,就会忽略该选项。那么重点是什么?它怎么能产生任何影响呢?它是否基本上是一个无操作的存根,以便在它执行某些操作时与旧版本的git兼容?

1 个答案:

答案 0 :(得分:4)

这是泄露的技术细节 - 实现--no-X选项的方法。不是单独定义--no-local,而是选项--local,它是noop,但它有--no-*版本。同样的方式(虽然在帮助中没有提到)你可以运行git clone --checkout ...但它不会影响任何东西,因为克隆默认检出。

PS:some long time ago it was not a default,所以使用它确实有意义。