Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix GIT error : HEAD: invalid reflog entry xxxxxxxxxxxxxxxx

Tags:

git

git-log

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?

like image 888
SnailgAry Avatar asked Sep 09 '16 10:09

SnailgAry


2 Answers

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.

like image 99
lucvoo Avatar answered Oct 18 '22 07:10

lucvoo


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.

like image 33
VonC Avatar answered Oct 18 '22 05:10

VonC