git rebase删除提交 [英] git rebase to remove a commit
问题描述
我的git存储库中具有以下更改历史记录:
I have the following change history in my git repository:
---X---Y---Z---A---B---C
我从代码Z的基础开始工作,进行了A,B和C的三个更改.每个更改都已作为Gerrit上的单独评论上传,并且每个更改都取决于它之前的更改.
I began working from a base of code Z and made three changes A, B and C. Each of these changes has been uploaded as separate reviews on Gerrit and each depends on the change before it.
在进行审核后,我想删除更改A,以便更改历史记录为:
Following a review I want to remove change A, so that my change history is:
---X---Y---Z---B---C
git rebase -i
和git commit
使其正常工作的正确流程是什么?
What is the correct flow of git rebase -i
and git commit
to get this to work?
我假设以下内容:
-
使用
git rebase -i HEAD~3
显示最后三个提交.显示文件内容:
Use
git rebase -i HEAD~3
to show the last three commits. This shows the file contents:
pick 1234567 Commit A message
pick 1a2b3c4 Commit B message
pick abcdefg Commit C message
pick 1234567 Commit A message
pick 1a2b3c4 Commit B message
pick abcdefg Commit C message
然后我可以删除第一行并保存文件以删除第一次提交.
I can then delete the first line and save the file to remove the first commit.
这就是我遇到的问题...如果尝试尝试git commit --amend
,我只能修改C的提交.因此,我不知道如何使用git push
This is where I get stuck... If I try to git commit --amend
I can only amend the commit of C. I thus don't know how to push my rebase change to Gerrit for review using repo upload .
or git push
我正在使用Gerrit 2.2,因此审阅页面上没有重新设置按钮.
I am using Gerrit 2.2 so there is no rebase button on the review page.
推荐答案
以下步骤现已为我工作:
The following steps have now worked for me:
-
使用git rebase -i HEAD〜3显示最后三个提交.显示文件内容:
Use git rebase -i HEAD~3 to show the last three commits. This shows the file contents:
pick 1234567 Commit A message
pick 1a2b3c4 Commit B message
pick abcdefg Commit C message
pick 1234567 Commit A message
pick 1a2b3c4 Commit B message
pick abcdefg Commit C message
然后我可以删除第一行并保存文件以删除第一次提交.
I can then delete the first line and save the file to remove the first commit.
A git log
现在显示了B和C在Z的基数之后的变化以及它们的新SHA-1值
A git log
now shows my B and C change after the base of Z, with their new SHA-1 values
然后我可以将每个更改单独推送到各自的评论:
I can then push each change individually to their respective reviews:
git push ssh://myserver:29418/project SHA1_of_B:ref/changes/123
git push ssh://myserver:29418/project SHA1_of_C:ref/changes/789
其中123
和789
分别是变更B和C的审阅编号.我的B和C更改每个都有新的补丁,可以正确地重新建立基础.
Where 123
and 789
are the review numbers for change B and C respectively. My B and C changes each have new patches which are properly rebased.
原来我的问题是仅仅了解我必须分别git push
两个更改.
Turns out my problem was just understanding that I had to git push
both changes individually.
这篇关于git rebase删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!