How to fix GIT error : HEAD: invalid reflog entry xxxxxxxxxxxxxxxx
Asked Answered
G

2

11

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?

Goodish answered 9/9, 2016 at 10:17 Comment(1)
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.Ferroelectric
B
26

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.

Brittanybritte answered 22/5, 2017 at 15:50 Comment(5)
this worked to clean up all the errors i was getting in git fsck --fullCatheterize
after fixing the repo with the above commadn, should I do git commit and git push?Ectoplasm
@Ectoplasm git commit and git push should now be OK (but better verify this with git fsck --full)Brittanybritte
It didn't work for me, I got fatal: bad tree object 727e795836deba03ac658a22f1e714ede7ea3c8aAnamariaanamnesis
If you don't want to actually expire anything except the broken entries, you can additionally use --expire=neverDisciple
C
1

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.

Cattycornered answered 21/2, 2021 at 1:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.