[Git] Troubleshoot on unable to read tree (<>)

When git checkout commit, found error Fix Unable to read tree like that.

It cause by dangling commit and dangling blob in repository.

Dangling commit:  Commit that isn’t directly linked to by any child commit, branch, tag or other reference

Dangling blob: A change that made it to the staging area/index, but never got committed.

These dragging commit and blob can found in command below:

git fsck --name-objects

Output:

 

Run command below to clean danging commit / blob and clean up repository

cd $REPO_PATH 
## Remove all danging commit and blob and GC collect. 
git reflog expire --expire=now --all 
git gc --prune=now 

## Clean up local old / conflict branch 
git remote prune origin

 

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.