git - revert range of commits (already pushed) with merge commits in between

╄→尐↘猪︶ㄣ 提交于 2021-01-28 05:36:51

问题


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

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.

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.

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).

Edit: 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?

Thanks


回答1:


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.

And in the local,

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

You can do both,

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


来源:https://stackoverflow.com/questions/47811491/git-revert-range-of-commits-already-pushed-with-merge-commits-in-between

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!