提问者:小点点

如何解决“致命:模棱两可的参数'head~1':未知的修订或路径不在工作树中”


我刚刚在master上有一个commit,而没有merge它进入remote,然后我想删除我的commit并保留我的更改文件,更改我的branch然后commit它们。

现在我已经使用了$git重置--soft head~1,但是我遇到了这个错误:

fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

共1个答案

匿名用户

head~1是指向“当前提交的父级”的方法

在您的情况下:(仅)主控上的提交没有父级。。。

如果您打算在另一个分支上提交此命令,只需创建另一个分支:

git checkout -b my/branch
# the above is a shortcut to :
git branch my/branch    # create a new branch `my/branch` on the current commit
git checkout my/branch  # switch to this branch

对于历史记录中的一个提交,“从master中删除提交”与“删除master”相同。

这样做没有什么坏处(您可以稍后重新创建它):git branch-d master
但是您也可以使用本地的master分支。