当你不小心使用了 git reset --hard HEAD^

会话总结

1. 使用 git reset --hard HEAD^ 后如何恢复撤销的 git commit 提交

知识点:

  • git reset --hard HEAD^ 会回退到前一个提交,并删除工作目录中的更改。
  • 通过 git reflog 查看操作历史记录,找到被回退的提交哈希值。
  • 使用 git reset --hard <commit_hash> 恢复到特定的提交。

操作步骤:

git reflog
git reset --hard <commit_hash>

2. 如何修改 git commit 的备注

知识点:

  • 使用 git commit --amend 修改最新提交的备注。
  • 使用 git rebase -i 交互式变基来修改任意提交的备注。
  • 使用 git rebase --continue 完成变基过程。

操作步骤:

  • 修改最新提交:

    git commit --amend
    
  • 修改任意提交:

    git rebase -i HEAD~<number_of_commits>
    # 将需要修改的提交的 `pick` 改为 `edit`
    git commit --amend
    git rebase --continue
    
posted @ 2024-07-04 17:10  无为而和  阅读(2)  评论(0编辑  收藏  举报