gpt4 book ai didi

git - git add '*.txt' 和 git add *.txt 有什么区别?

转载 作者:太空狗 更新时间:2023-10-29 13:20:46 27 4
gpt4 key购买 nike

我只是在处理 git 类(class) https://try.github.io/levels/1/challenges/1在代码学校,对 git add '*.txt' 和 git add *.txt 的不同行为感到困惑。

不带引号的字符串并没有添加所有内容。 git rm 也一样。为什么会这样?或者它只是特定于网络版本?

最佳答案

如“Wildcards inside quotes"”中所述,通配在单引号或双引号中均无效。

Fileglobs (e.g. *.c) can be given to add all matching files

  • 如果没有引号,将由当前文件夹中的 shell 完成通配。
  • 使用引号,它可以防止 shell 通配符,并允许 Git(与我最初的回答相反)处理 pathspec "*.txt"跨越所有工作树(而不仅仅是当前文件夹)。

您可以在 t/t4010-diff-pathspec.sh#L53-L56 中查看示例


Commit 8300016通过 Junio C Hamano (gitster)添加另一种防止文件通配的方法,加上一些解释:

gitcli: contrast wildcard given to shell and to git

People who are not used to working with shell may intellectually understand how the command line argument is massaged by the shell but still have a hard time visualizing the difference between letting the shell expand fileglobs and having Git see the fileglob to use as a pathspec.

Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell. These two mean different things:

--------------------------------
$ git checkout -- *.c
$ git checkout -- \*.c
--------------------------------
  • The former lets your shell expand the fileglob, and you are asking the dot-C files in your working tree to be overwritten with the version in the index.
  • The latter passes the *.c to Git, and you are asking the paths in the index that match the pattern to be checked out to your working tree.

关于git - git add '*.txt' 和 git add *.txt 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33461996/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com