npostavs
npostavs

Reputation: 5037

Is it possible to prevent git from immediately removing the reflog of deleted branches?

git branch -d <branch> deletes the branch and also it's reflog (in .git/logs/refs/heads/<branch>). Yes, you can probably recover the branch from HEAD's reflog, but why throw away the branch's reflog immediately? Surely it would be more sensible to keep it around and gc it later. This would also give a much easier way to undelete branches (no hunting through HEAD's reflog).

  1. Is this is a good idea?

  2. Assuming the answer to 1 isn't "no, it's a horrible idea", can this be achieved by config options (I didn't find any) or by some combination of plumbing commands?

Upvotes: 3

Views: 86

Answers (1)

torek
torek

Reputation: 489848

I don't think it's a bad idea, and the reflog entries will go away on their own after the usual expiration, so I'm not sure why git branch -d deletes the reflogs.

I verified that git update-ref -d does not delete the reflog, so yes, you can achieve the desired affect through plumbing commands. Write whatever tests you like before invoking git update-ref, then use -d to delete if the tests pass.

Upvotes: 4

Related Questions