为何无法正确执行git reset –hard HEAD^

原文地址:https://www.hksilicon.com/articles/595842?lang=cn

Git入门书里都会提到放弃最后一次的commit而回复到再上一次commit的指令:

 git reset --hard HEAD^ 

但是这个指令在Windows的命令提示字符cmd.exe里却无法执行,会出现错误:

 D:\git-root\test>git reset --hard HEAD^ More? More? fatal: ambiguous argument 'HEAD ': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git  [...] -- [...]' 

今天终于弄清楚了:^是cmd.exe的escape字符,属于特殊字符,命令里要用到文字 ^ 时必须用双引号把它夹起来,因此只要如下就可以正确执行:

 git reset --hard HEAD"^" 

或者:

 git reset --hard "HEAD^" 

或许有人会觉得奇怪:为何不直接使用bash就好,因为几乎所有的教学或书籍都是在bash环境里展示的。最主要的原因是团

猜你喜欢

转载自blog.csdn.net/m0_37477061/article/details/83004887