git add --ignore-removal的快捷方式是什么?

7

多年来,我一直在提交更改之前输入git add .。从下面的消息中我了解到,现代化的等效方式应该是git add --ignore-removal <pathspec>,这种方式稍微有点啰嗦。在即将发布的2.0版本中是否有办法恢复旧的行为,或者至少在当前版本中静音此消息?

$ git add .
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'log/sunspot-solr-development.log.lck' that are
removed from your working tree are ignored with this version of Git.

* 'git add --ignore-removal <pathspec>', which is the current default,
  ignores paths you removed from your working tree.

* 'git add --all <pathspec>' will let you also record the removals.

Run 'git status' to check the paths you removed from your working tree.

我认为这里没有任何配置,手册只是说默认值将变为“-A”。您可以将类似于“git a”的别名设置为“git add --ignore-removal”。 - Dogbert
谢谢Dogbert。我已经在我的.gitconfig中添加了[alias] a = add . --ignore-removal。 - Abram
为什么不在git@vger.kernel.org上请求“--ignore-removal”选项的快捷方式? - krlmlr
3
多年来我一直使用git add .。现在收到这些“警告”,并想知道我是否错误地使用了Git?每天肯定有数十万次提交,不可能所有人都打出git add --ignore-removal。我甚至不确定那是什么意思。有人知道为什么他们做出了这个改变吗? - Meltemi
@Meltemi,我已经添加了一个答案来解释--ignore-removal选项。 - VonC
1个回答

5
你看到的警告来自 commit ccc663b,它优化了 commit 45c45e3
第二个提交确实提到了:

git add: 开始准备将 "git add <pathspec>..." 默认为 "-A"

计划最终使 "git add" 在命令行中有路径规范时,假装给出 "-A"。
为了实现这个转换,人们需要学会说 "git add --no-all subdir/",当他们想忽略已删除的路径,如 "subdir/z",或者当他们想将整个目录的状态作为一个整体时,他们需要说 "git add -A subdir/"。
没有任何参数的 "git add" 将继续是无操作的。
因此,"git add ." 的现代等效方式实际上是 "git add -A .":请参见 "如何使 Git 默认使用“add --all”?"。
Meltemi 评论

我甚至不确定那是什么意思?有人知道他们为什么做出了这个改变吗?

我提到的提交说明了 --ignore-removal 选项:

当没有 "-u" 或 "-A" 选项时运行 "git add subdir/",例如:

$ edit subdir/x
$ create subdir/y
$ rm subdir/z
$ git add subdir/

该命令未注意到从工作树中删除的路径(例如subdir/z)。有时会让新手感到困惑,因为可以说“git add”被告知记录整个“subdir/”的当前状态,而不是与该路径规范匹配的工作树中存在的路径的当前状态(后者根据定义排除了“subdir/z”的状态,因为它不存在于工作树中)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接