John Oxley
John Oxley

Reputation: 14990

What happens to commits left behind from git branch -D

I worked on an experimental branch and now want to delete it. Running git branch -d experimental outputs

error: The branch 'experimental' is not fully merged.
If you are sure you want to delete it, run 'git branch -D experimental'.

After running deleting the branch with -D, what happens to the commits left behind?

Upvotes: 0

Views: 325

Answers (1)

Gabriele Petronella
Gabriele Petronella

Reputation: 108121

They stay where they are in the git graph, simply there's no explicit reference to them anymore.

If you have the hash of a specific commit in that branch you can still refer to it, try for instance

git log <commit-sha>

where <commit-sha> is the hash of the commit.

That being said, also note that those "dangling" commits may disappear in the future when someone runs git prune (directly or via git gc, which in modern versions of git is run automatically when needed), which deletes all the unreachable objects from the graph.

Upvotes: 1

Related Questions