修订提交恢复为上一次提交

问题描述 投票:0回答:1

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

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

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:[email protected]/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时,它表示致命的坏对象。

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

谢谢。

git patch gerrit git-rebase amend
1个回答
0
投票

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

git checkout ssh:[email protected]/development refs/changes/1/12345/10 && git checkout FETCH_HEAD
git commit --amend
git push HEAD:refs/for/master

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

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

© www.soinside.com 2019 - 2024. All rights reserved.