修改后的提交恢复为先前的提交 [英] Amended commits revert to previous commit

查看:88
本文介绍了修改后的提交恢复为先前的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与master分支一起的仓库.我在一次提交中修改了补丁集1到10.现在,我修改了该提交中的第11个补丁集,并以gerrit推送了代码.我想将提交还原回第10次提交并推送.我如何还原,就像看到git log一样,它没有列出该补丁集中的提交.而是将其作为单个提交.

I have a repo with master branch. I have patch-sets 1 to 10 amended in a single commit. Now I have amended the 11th patch-set in that commit and pushed the code in gerrit. I want to revert the commit back to 10th commit and push. How do I revert, as if I see git log, it does not list the commits in that patch-set. But it rather takes it as a single commit.

我已经解释了下面的操作顺序.

I have explained the sequence of actions done below.

Sequence of actions
1. Initially for patch-set #1 
git clone repo
made changes to code 
git commit 
git push HEAD:refs/for/master => pushes to gerrit
Let us assume gerrit patch# generated is 12345

2. mkdir new_dir
git clone repo
git checkout ssh:user@gerrit1.xxx.com/development refs/changes/1/12345/1 && git checkout FETCH_HEAD
made modifications for patch-set 2 on patch-set 1
git commit --amend
git push HEAD:refs/for/master => pushes to gerrit 

Now gerrit patch#12345 has following commits/patch-sets
1, 2

3. Repeated step 2 for patch-sets 3 to 11
Now gerrit patch#12345 has following commits/patch-sets
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

4. Got to know path-set 11 is redundant, has to be reverted, so that patch-set#10 is the latest and 11 should be discarded, so that gerrit patch#12345 has commits/patch-sets 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 only (not 11).


How do I achieve step 4?

当我尝试使用commit-id git rebase -i时,它说是致命的坏对象.

When I tried git rebase -i with the commit-id it says fatal bad object.

请让我知道如何使用git命令解决此问题,或者应该手动进行.

Please let me know how to resolve this using git commands, or should I do it manually.

谢谢.

推荐答案

答案在您的问题中.无需签出补丁程序集1,您只需要取回补丁程序集10.

The answer is in your question. Instead of checking out patchset 1 you just need to fetch back patchset 10.

git checkout ssh:user@gerrit1.xxx.com/development refs/changes/1/12345/10 && git checkout FETCH_HEAD
git commit --amend
git push HEAD:refs/for/master

您需要修改补丁集10才能再次推送它,因为Gerrit不允许您重新推送相同的补丁集,之后您可以提交补丁集11.

You will need to amend your patchset 10 for you to be able to push it again as Gerrit will not allow you to re-push the same patchset, after this you can submit patchset 11.

或者,您可以检查您的reflog并在其中找到补丁集11.但是最简单的方法是从Gerrit下载命令中获取命令

Alternatively you could inspect your reflog and find patchset 11 in there. But the easiest way is to get the command from the Gerrit Download Commands

这篇关于修改后的提交恢复为先前的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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