Git 为什么通过插入符号表示的提交排除实际上不排除命令提示符中的提交?

Git 为什么通过插入符号表示的提交排除实际上不排除命令提示符中的提交?,git,cmd,Git,Cmd,发件人: 排除 ^(插入符号)符号 要从提交中排除可访问的提交,请使用前缀^表示法。例如,^r1 r2表示可从r2访问的提交,但不包括这些提交 可从r1(即r1及其祖先)访问 我有一个测试存储库,我在其中试用了这种语法。就本问题而言,它包括三个正常提交: git log --pretty=oneline topic1 77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1

发件人:

排除

^(插入符号)符号

要从提交中排除可访问的提交,请使用前缀^表示法。例如,^r1 r2表示可从r2访问的提交,但不包括这些提交 可从r1(即r1及其祖先)访问

我有一个测试存储库,我在其中试用了这种语法。就本问题而言,它包括三个正常提交:

git log --pretty=oneline topic1
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1
b5803f6c59cbc9ae6b4bba81b0d5ad8cfbd8f23a start of topic 1
75400b34ebc0936dd28513c686c8adb526f063e6 (origin/master) Initial Commit
让我们尝试排除除最近提交之外的所有提交:

git log --pretty=oneline ^topic1~ topic1
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1
b5803f6c59cbc9ae6b4bba81b0d5ad8cfbd8f23a start of topic 1
75400b34ebc0936dd28513c686c8adb526f063e6 (origin/master) Initial Commit
它不起作用。这似乎很奇怪,因为我们完全遵循插入符号符号。假设我们尝试改用提交哈希:

git log --pretty=oneline ^b5803 topic1
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1
b5803f6c59cbc9ae6b4bba81b0d5ad8cfbd8f23a start of topic 1
75400b34ebc0936dd28513c686c8adb526f063e6 (origin/master) Initial Commit
仍然不起作用。相比之下,其他符号的作用与预期相同:

git log --pretty=oneline topic1 --not topic1~
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1

git log --pretty=oneline topic1~..topic1
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1

为什么插入符号排除符号的行为方式不同?

命令提示符将插入符号视为转义字符-也就是说,插入符号使命令提示符将其后面的字符解释为文字。这会导致插入符号在此实例中无效。在命令提示下,您可以在正常情况下使用两个插入符号(^^):

git log --pretty=oneline ^^topic1~ topic1
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1

命令提示符将插入符号视为转义字符-即,插入符号使命令提示符将其后面的字符解释为文字。这会导致插入符号在此实例中无效。在命令提示下,您可以在正常情况下使用两个插入符号(^^):

git log --pretty=oneline ^^topic1~ topic1
77ffe1ada25be4b465be9fc9b46f63981ecc8b16 (origin/topic1, topic1) second commit of topic 1

你没有说你正在使用哪个平台。但是让我猜猜:您在Windows上,并且您正在Windows命令行提示符CMD中键入这些命令

CMD是一种奇怪的野兽。特别是,插入符号
^
是某种转义字符。要将单个插入符号传递给调用的程序,必须在命令行中键入两个插入符号:

git log --pretty=oneline ^^topic1~ topic1
我通常不使用
^
,而是使用
--not

git log --pretty=oneline topic1 --not topic1~

但它有自己的警告,最重要的是,它的影响扩展到命令行上给出的所有后续引用,而不仅仅是下一个引用。这就是为什么与原始示例相比,必须交换两个ref规范的原因。

您没有说明正在使用哪个平台。但是让我猜猜:您在Windows上,并且您正在Windows命令行提示符CMD中键入这些命令

CMD是一种奇怪的野兽。特别是,插入符号
^
是某种转义字符。要将单个插入符号传递给调用的程序,必须在命令行中键入两个插入符号:

git log --pretty=oneline ^^topic1~ topic1
我通常不使用
^
,而是使用
--not

git log --pretty=oneline topic1 --not topic1~
但它有自己的警告,最重要的是,它的影响扩展到命令行上给出的所有后续引用,而不仅仅是下一个引用。这就是为什么与原始示例相比,必须交换两个ref规范的原因