0

I accidentally pushed the empty commit into Github When I do

git log 

I cam see 3 commits including empty commit

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

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 ?

Priyanka Anjuri
  • 381
  • 1
  • 3
  • 10

1 Answers1

1

Lets say I have three commits:
first commit
second commit [which is empty]
third commit

Then on doing:
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!!

S_learner
  • 334
  • 2
  • 8
  • git rebase -i HEAD~2 is not showing me any empty commit so its just displaying commit 1 and commit 3 where commit 2 is empty here ? – Priyanka Anjuri Dec 05 '18 at 21:41