Git: remove dead branch after reinstalling?

I have the following git branches master and dev:

   *master*
      |
A--B--C
   \--D--E
         |
       *dev*

      

After rebooting dev to master, I have:

   *master*
      |
A--B--C--D'--E'
   \--D--E   |
             |
           *dev*

      

So D and E remain in the dead branch. How do I remove them?

+3


source to share


2 answers


You don't need to: because commits D

and E

don't have a name 1 pointing to them, they are eligible for garbage collection. Eventually git will run git gc

and throw them away for you.

If you want to speed this up you can run it git gc

yourself, but then footnote 1 comes into play. :-)


1 This is not entirely true. While the branch name dev

now contains the commit id E'

(copy), there are two reflog entries, one for dev

and one for HEAD

, that allow you (and git) to find commit E

. There is also a semi-special name ORIG_HEAD

that continues until something else replaces its content (like another rebase or git merge

).



By default, most log entries persist for 30 days or 90 days depending on whether a commit is available for the current branch. Once the reflog file expires, the object is a candidate for garbage collection.

As another precaution, git gc

leaves "free objects" alone if they are at least two weeks old (by default - this is configurable and there is an option --prune=

to override this as well). So in general, for a nominally abandoned object to get away with, it's:

  • must be at least two weeks old;
  • Any number of reflog entries must have been completed (usually 30 days); and
  • there should be no alternative names to support it.

(And, of course, it git gc

should, although git automatically starts when it "looks promising".)

+5


source


Nothing breaks if you have additional commits, they are just there if you want to navigate your reflog or otherwise reference them later.

However, if you want to force the removal of additional commits and other unnecessary objects, you can use git gc

. If you want it to remove as many extra commits / objects as possible (and don't care about speed) you can use git gc --aggressive

.



Note. Technically, D and E are no longer in the branch. Branches are just pointers to commit, they have no history of their own (other than the history of the specific commits they point to). As a result, when you compiled dev, git left the D and E points in case you want to access them later, even if they are no longer on the branch.

0


source







All Articles