撤消 git pull,如何将 repos 恢复到旧状态 [英] Undo git pull, how to bring repos to old state

查看:44
本文介绍了撤消 git pull,如何将 repos 恢复到旧状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以恢复或撤消 git pull 以便我的源/存储库回到执行 git pull 之前的旧状态?我想这样做是因为它合并了一些我不想这样做的文件,而只合并了其他剩余的文件.所以,我想取回那些文件,这可能吗?

Is there any way to revert or undo git pull so that my source/repos will come to old state that was before doing git pull ? I want to do this because it merged some files which I didn't want to do so, but only merge other remaining files. So, I want to get those files back, is that possible?

我想撤消 git merge 以进行澄清.看到一些答案后,我做了这个

I want to undo git merge for clarification. After seeing some answers, I did this

git reflog
bb3139b... HEAD@{0}: pull : Fast forward
01b34fa... HEAD@{1}: clone: from ...name...

现在,我该怎么办?做 git reset --hard 可以吗?不想再搞砸了,求详细步骤?

Now, what should I do ? Doing git reset --hard is OK ? I don't want to screw it again, so asking for detailed steps ?

推荐答案

Running git pull 执行以下任务,顺序:

Running git pull performs the following tasks, in order:

  1. git fetch
  2. git merge

合并步骤合并了已设置为要合并到您的配置中的分支.您想撤消 merge 步骤,但可能不是 fetch(没有多大意义,也没有必要).

The merge step combines branches that have been setup to be merged in your config. You want to undo the merge step, but probably not the fetch (doesn't make a lot of sense and shouldn't be necessary).

要撤消合并,请使用git reset --hard 将本地存储库重置为以前的状态;使用 git-reflog 找到 SHA-1 之前的状态,然后重置为它.

To undo the merge, use git reset --hard to reset the local repository to a previous state; use git-reflog to find the SHA-1 of the previous state and then reset to it.

警告

本节中列出的命令删除所有未提交的更改,可能会导致工作丢失:

The commands listed in this section remove all uncommitted changes, potentially leading to a loss of work:

git reset --hard

或者,重置到特定时间点,例如:

Alternatively, reset to a particular point in time, such as:

git reset --hard master@{"10 minutes ago"}

这篇关于撤消 git pull,如何将 repos 恢复到旧状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆