gpt4 book ai didi

Git - 我怎样才能回到初始提交?

转载 作者:行者123 更新时间:2023-12-04 01:16:21 24 4
gpt4 key购买 nike

我有一个只有一次提交的 git 仓库。在我本地的 master 分支中,我不小心做了一个git commit --amend 所以现在我收到一条消息说

On branch master 

Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.

如何丢弃修改后的提交并返回到原始提交?我想让我的本地 master 和 origin/master 保持最新状态,无需提交任何内容

最佳答案

您可以使用 reflogmaster 重置为它引用的提交之前当前:

git reset --hard master@{1}

在这种情况下,reflog 是真正的救星。非常值得在 Git Book 中阅读它:

At some point in your Git journey, you may accidentally lose a commit. Generally, this happens because you force-delete a branch that had work on it, and it turns out you wanted the branch after all; or you hard-reset a branch, thus abandoning commits that you wanted something from. Assuming this happens, how can you get your commits back? [...]

Often, the quickest way is to use a tool called git reflog.

关于Git - 我怎样才能回到初始提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63298641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com