Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will git prune a commit that is branchless but is tagged?

Tags:

git

From what I understand, git will occasionally prune commits that are not reachable by any branches. However, does it still delete those commits, even if they have tags?

I was thinking of making some one off commits and tagging them, but only ever single commits, so no need for them to have branches attached.

like image 611
Jon Avatar asked Dec 18 '22 14:12

Jon


1 Answers

No, it will not delete any commits which are referenced by branches, tags, the index and so on or any parent of those commits. See "Notes" section of the help page for git gc:

git gc tries very hard to be safe about the garbage it collects. In particular, it will keep not only objects referenced by your current set of branches and tags, but also objects referenced by the index, remote-tracking branches, refs saved by git filter-branch in refs/original/, or reflogs (which may reference commits in branches that were later amended or rewound).

If you are expecting some objects to be collected and they aren’t, check all of those locations and decide whether it makes sense in your case to remove those references.

like image 110
lucash Avatar answered Dec 31 '22 15:12

lucash