4

On my local clone of a git repo, when a reference is deleted (or renamed), the reflog attached to the old name is deleted.

I couldn't find an option which states "keep log for deleted references".

Question

Is there a way to keep the reflog files for deleted references ?

Cleaning and gc could still follow the parameters for reflog entries, unreachable objects, etc ...

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Well, if you're thinking of deleted commits, the best thing to do would be to keep alive a branch which references those commits. – Tim Biegeleisen Aug 29 '18 at 14:13

1 Answers1

5

As far as I can tell, git does not provide a way to do this. I don't know the reasoning; it would of course be nice to keep the branch's reflog for the usual retention period, but not knowing the nuts and bolts of how reflog expiration normally works I can't say if there's a solid reason why that would be too difficult. (Or maybe it would be a problem in the event a new branch with the same name is created?)

Whatever the reason, the docs specify that the log is deleted (https://git-scm.com/docs/git-branch) and do not indicate any way to change the behavior. I guess you could manually copy the reflog file (.git/logs/refs/...) to preserve the information, but it's certainly not a user-friendly approach.

In practice, you're basically limited to whatever entries might incidentally be in the HEAD reflog. So, I guess if you're not sure that you no longer need a more detailed history of the branch, don't delete it yet.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • 1
    There was discussion at some point on the Git mailing list about keeping reflogs even when deleting a branch. It's going to have to wait for a real reference database, I think, as there are a lot of stubborn corner cases that would go away if reflogs weren't just files in a directory tree... – torek Aug 29 '18 at 15:18
  • @torek Don’t know if this is the one you thought of but it is at least relevant: [Keep reflogs for deleted (remote tracking) branches?](https://lore.kernel.org/git/CAPMMpog=qBwLrxss_ci6ZMM+AjbdrF8tszXLW7YH1Zqr+m7mPQ@mail.gmail.com/) – Guildenstern May 05 '23 at 08:54