【发布时间】:2020-04-29 23:21:28
【问题描述】:
我有一个带有 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: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 时,它说是致命的坏对象。
请告诉我如何使用 git 命令解决这个问题,或者我应该手动解决。
谢谢。
【问题讨论】:
-
我不确定您的情况如何,但是当您修改此提交时,您现在“看不到”它们。用 reflog 来支持你的历史怎么样?
-
“我在一次提交中修改了补丁集 1 到 10。”你的意思是你在一次提交中压扁了它们?你想恢复那个提交吗?
-
@dunajski 我将在这里解释情况。我有主分支的干净回购。我进行了更改并提交了 #1 并将其推送到 gerrit 中的单独补丁集中。后来我做了一些补充,然后对之前的 commit#1 进行了修改,这将是 commit#2,并且持续了几个月。现在我在 git 日志中可见的单个提交 commit#10 中有 10 个补丁集。但在 gerrit 中,我有单独的 10 个补丁集。我已经进行了第 11 次提交并推送了 gerrit,但想将其恢复为提交#10。我正在使用gerrit。可能吗。 (问题编辑为使用 gerrit)
-
你可以试试----> git reset --soft HEAD~1
-
@Muzzamil 不,这无济于事,因为 git 将整个 gerrit 补丁视为单个提交。 @ Muzzamil 和@ dunajski 我已经修改了问题以使其更清楚。如果需要更多详细信息以便理解,请告诉我。
标签: git patch gerrit git-rebase git-amend