8

I have met an error before(GIT error: object file is empty)

error_object_file_is_empty

Then I used the method mentioned in how to fix GIT error: object file is empty? After I updated the HEAD pointer to a good object, it does work .but when I restart the machine ,the same error(object file is empty) occured. I tried find . -type f -empty -delete to delete all the empty files and type git fsck --full then the new error occured.(GIT error: HEAD: invalid reflog entry xxxxxxxxxxxxxxxx)

error_invalid_reflog_entry

Is there anything wrong with my GIT? or just because of my bad operations? And how to fix this problem?

Machavity
  • 28,730
  • 25
  • 78
  • 91
SnailgAry
  • 81
  • 1
  • 3
  • First, please backup your whole repository just in case. Next, can you please try 'git update-ref -d' inside of the repository. This might help you overcome this issue, but I am not all that familiar with this specific one. If this doesn't work, let me know so I can try to assist more.. If its right, let me post an answer so you can mark it. – Daniel Anner Sep 09 '16 at 14:57

2 Answers2

16

The command to use is git reflog expire --stale-fix --all

The magic here is in the --stale-fix option which will prune any reflog entries that point to an unreachable commit and that refers to a missing object.

lucvoo
  • 420
  • 4
  • 15
0

The command to use is git reflog expire --stale-fix --all

But make sure to use Git 2.31 (Q1 2021)

"git reflog expire --stale-fix"(man) can be used to repair the reflog by removing entries that refer to objects that have been pruned away, but was not careful to tolerate missing objects.

See commit c809798 (10 Feb 2021) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit e68f62b, 17 Feb 2021)

reflog expire --stale-fix: be generous about missing objects

Signed-off-by: Johannes Schindelin

Whenever a user runs git reflog(man) expire --stale-fix, the most likely reason is that their repository is at least somewhat corrupt.
Which means that it is more than just possible that some objects are missing.

If that is the case, that can currently let the command abort through the phase where it tries to mark all reachable objects.

Instead of adding insult to injury, let's be gentle and continue as best as we can in such a scenario, simply by ignoring the missing objects and moving on.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283