3

What is a dangling tree?

I am new to Git and I am using the latest Git-GUI for Windows. The dangling tree is reported when I do a Git-GUI Repository : Verify Database after creating a new repository:

Git fsck dangling tree

This is my newly created empty repository:

enter image description here

It says 'Success' but when I search for 'dangling tree' there seem to be reports of problems and when I search for 'What is a dangling tree' I get no results. I would like to know in general what a dangling tree is, what it is in this particular instance and is this one a problem.

soid
  • 541
  • 8
  • 15
  • 1
    possible duplicate of [git's semi-secret empty tree](http://stackoverflow.com/questions/9765453/gits-semi-secret-empty-tree) – Hauleth Oct 25 '13 at 10:55
  • @ŁukaszNiemier I do not see anything about "dangling tree" on that page. – soid Oct 25 '13 at 11:01

1 Answers1

7

What is a dangling tree?

"Dangling" is git's slightly quirky spelling of "unreferenced".

4b825dc642cb6eb9a060e54bf8d69288fbee4904 in new repository

That's the SHA of the empty-tree, git mktree </dev/null will make it. Something, somewhere, in your repo's initialization has made that, perhaps looking for a null root commit, or perhaps you have a template repository with that in it, or some status-inquiry command has done it.

If git fsck's notice is irksome the easy fix is to reference it, and you can even maybe get some use out of it with

git commit-tree -mempty\ tree 4b825dc642 | xargs git tag empty
Community
  • 1
  • 1
jthill
  • 55,082
  • 5
  • 77
  • 137
  • Thank you. It is becoming clearer. So according to the accepted answer to that question the best practice is to immediately do an initial empty commit and then the dangling tree will be referenced and we will have a clean start to the repository. So after that is it true that any dangling tree I find is something that needs to be fixed? – soid Oct 25 '13 at 12:22
  • 2
    No, there's no need to worry about dangling items, they're just things that were put there for some purpose that are no longer needed. git will eventually garbage-collect them. – jthill Oct 25 '13 at 13:34
  • 1
    If you run `git gc` from the command line (I am not sure about the GUI), it will clean up the dangling tree. – Daniel Wisehart Oct 21 '16 at 18:02