删除最后一次从 GitHub 拉取的操作

3

我正在develop分支上工作。我提交了我的代码并切换到另一个分支feature/2.10.9。 我需要从feature/2.10.9获取最新代码,但不小心运行了以下命令

git pull origin develop

取代
git pull origin feature/2.10.9

已从develop分支拉取最新的代码。Git状态显示以下输出:

On branch feature/2.10.9
Your branch is ahead of 'origin/feature/2.10.9' by 5 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

但我不想将develop分支的更改推送到feature/2.10.9。 我该怎么做才能中止当前的推送。

谢谢。


"$git checkout ." 你会失去你的更改,但你可以再次切换分支。如果你想保留你的更改,请使用 "$git stash"。 - Mathias Dewelde
@Mathias Dewelde:我的本地没有任何更改,它仍然无法工作,仍然显示“Your branch is ahead of 'origin/feature/2.10.9' by 5 commits. (use "git push" to publish your local commits)”。 - user3401408
“git checkout” 不会有任何作用,因为暂存区中没有文件。 “pull” 将会直接合并这些文件。 - gravetii
2个回答

5

您需要基本上撤消合并操作,通过运行 git pull origin develop 而不是 git pull origin feature/2.10.9

首先在本地执行

git reflog 获取有问题的拉取前(最后一个稳定状态)的提交的 SHA-1

要撤消合并 -

git reset --hard <SHA-1 of commit obtained above>

请注意,所有这些步骤都应在您位于feature/2.10.9分支时完成。完成这些步骤后,您将处于与错误合并之前相同的状态。现在您可以安全地运行git pull origin feature/2.10.9,它会从远程获取并合并最新版本的feature/2.10.9

@gravetii- 嘿兄弟,感谢你的帮助。非常感谢 :) - user3401408

5

仅需一键重置

git reset --hard HEAD^1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接