git - 恢复提交范围(已推送),中间有合并提交 [英] git - revert range of commits (already pushed) with merge commits in between

查看:35
本文介绍了git - 恢复提交范围(已推送),中间有合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,要明确的是,我没有找到我的问题的正确答案!!

First, to be clear, I didn't find the right answer to my issue!!

说明我已经(非常意外地)将一个分支推送到 master 并且一些文件丢失了:-S(它们不在推送的分支中).我想通过回滚到第 n 个以前的提交来检索它们.

Description I've pushed (very accidentally) a branch into master and some files were lost :-S (they weren't in the pushed branch). I'd like to retrieve them by rolling back to a nth-previous commit.

如何将 Git 存储库恢复到以前的提交? 据说使用 revert,我同意.但是当我执行 git revert <nth-previous_right_commit> 时,丢失的文件仍然丢失,如果根据 revert 定义它undoes 更改,在这种情况下,这似乎不会发生.

In How to revert Git repository to a previous commit? it is said to use revert, which I agree. But when I do git revert <nth-previous_right_commit> the missing files are still missing and, if according to revert definition it undoes changes, in this case that doesn't seem to happen.

如果我执行git checkout <nth-previous_right_commit>,我会得到丢失的文件返回,但我无法进行有效的提交(我的意思是,git commit没有说要提交:-S).

I get the missing files back if I do git checkout <nth-previous_right_commit>, but I can't do an effective commit (I mean, git commitsays nothing to commit :-S).

以前我没有注意到我要检索的快照是第 4-5 次前一次提交,但中间有合并提交,因此执行 git revert -m 1 <nth-previous-commit>..HEAD 抱怨没有合并提交.

Previously I didn't notice the snapshot I want to retrieve is the 4th-5th previous commit but there are merge commits in between, so doing a git revert -m 1 <nth-previous-commit>..HEAD complaints about no merge commits.

那么,如何通过中间的合并提交来完成恢复?

So, how can accomplish the revert with merge commits in between?

谢谢

推荐答案

使远程存储库master 位于它应该在的位置:

To make master of the remote repository where it should be:

git push origin -f <nth-previous_right_commit>:master

如果您的远程存储库设置了访问控制,您可能需要强制推送权限.

You may need the force-push right if your remote repository has setup access control.

在本地,

git checkout master
git reset <nth-previous_right_commit> --hard

两者都可以,

git checkout master
git reset <nth-previous_right_commit> --hard
git push origin -f master:master

这篇关于git - 恢复提交范围(已推送),中间有合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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