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

时间:2019-01-10 13:33:45

标签: git cmd

来自https://git-scm.com/docs/git-rev-parse#_specifying_ranges

  

提交排除项

     

^(脱字符号)符号

     

要从提交中排除可到达的提交,请使用前缀^表示法。例如。 ^ 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

它没有用。考虑到我们完美地遵循了插入符号,这似乎很奇怪。假设我们尝试改用commit hash:

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

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

2 个答案:

答案 0 :(得分:2)

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

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

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

我通常远离^并改用--not

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

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

答案 1 :(得分:0)

命令提示符将脱字符号视为转义字符-即,克拉使命令提示符将其后的字符解释为文字。这导致插入符号在这种情况下不起作用。在命令提示符下,通常情况下,只要使用一个,就可以使用两个插入符号(^^):

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