为什么我不能在不指定分支的情况下将 HEAD^ 推到原点?

Why can't I push HEAD^ to origin without specifying a branch?

在我的功能分支中:

$ git push origin HEAD
Counting objects: 6, done.
...

但是:

$ git push origin HEAD^
fatal: remote part of refspec is not a valid name in HEAD^

为什么我需要指定分支(与普通 HEAD 不同):

$ git push origin HEAD^:my_branch
Everything up-to-date

参见 git help push。通常,refspec 参数由冒号分隔的两部分组成。冒号和目标 ref 可以省略:

If git push [<repository>] without any <refspec> argument is set to update some ref at the destination with <src> with remote.<repository>.push configuration variable, :<dst> part can be omitted—such a push will update a ref that <src> normally updates without any <refspec> on the command line. Otherwise, missing :<dst> means to update the same ref as the <src>.

但是,HEAD^ 未配置为更新任何 ref,并且在远程上尚不存在,因此 git 不知道要用它更新哪个远程 ref。