【问题标题】:How can I solve "fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree"?如何解决“致命:不明确的参数'HEAD~1':未知修订或路径不在工作树中”?
【发布时间】:2023-03-25 23:32:01
【问题描述】:

我在master 上只有 一个 提交,还没有将它合并到 remote 中。我想删除我的提交,保留我更改的文件,更改我的分支并提交它们。

现在我使用了git reset --soft HEAD~1,但我遇到了这个错误:

致命:不明确的参数“HEAD~1”:未知修订版或路径不在工作树中。 使用 '--' 将路径与修订分开,如下所示: 'git [...] -- [...]'

【问题讨论】:

  • 你的意思是,目前,你的master 分支在其历史中只有一个提交?
  • 是的,完全是@LeGEC

标签: android git git-bash


【解决方案1】:

HEAD~1 是一种指向“当前提交的父级”的方式

在您的情况下:master 上的(唯一)提交没有父级 ...


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

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 分支一起闲逛。

【讨论】:

    【解决方案2】:

    另一种方法是修改第一次提交:

    # Make your change in the file(s)
    git add file_changes
    git commit --amend --no-edit
    

    资源:How can I add a file to the last commit in Git?

    【讨论】:

      猜你喜欢
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 2021-09-15
      • 2020-07-24
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多