简体   繁体   English

压扁/修复GIT中的空提交

[英]Squash/Fixup the empty commit in GIT

I accidentally pushed the empty commit into Github When I do 我不小心将空提交推入Github中

git log 

I cam see 3 commits including empty commit 我可以看到3次提交,包括空提交

Commit 3 : XXXX
Commit 2[Empty commit]: XXXXX
Commit 1 : XXXX

When I do 当我做

git rebase -i HEAD~3

I am getting: 我正进入(状态:

fatal: Needed a single revision
invalid upstream 'head~3'

Which means its not showing empty commit 这意味着它没有显示空提交

When I do: 当我做:

git rebase -i HEAD~2

I am getting: Commit 1 and Commit 3 我得到:提交1和提交3

Empty commit is not shown while doing rebase 进行基础调整时不显示空提交

I tried cherry-pick rebase --keep empty 我尝试了重选樱桃-保持空

How can I squash/fixup the empty commit[Commit 2 in the example] using rebase ? 如何使用rebase压缩/修复空的commit [在示例中为Commit 2]?

Lets say I have three commits: 可以说我有三个提交:
first commit 第一次提交
second commit [which is empty] 第二次提交[为空]
third commit 第三次提交

Then on doing: 然后在做:
git rebase -i HEAD~2 git rebase -i HEAD〜2

It will show the last two commits on the editor like this: 它将在编辑器上显示最后两个提交,如下所示:
second commit [this empty commit will be shown but as commented line, started with #] 第二次提交 [此空提交将显示,但以注释行开头,以#开头]
third commit 第三次提交

Now just save and quit the editor, then check, empty commit should not be visible in the logs. 现在,只需保存并退出编辑器,然后检查,空的提交应该在日志中不可见。

Just push the changes forcefully to remote to remove it from there as well. 只需强行将更改推到远程也可以将其从那里删除。

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM