Search code examples
gitgit-reflog

keep reflog for deleted references


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 ...


Solution

  • 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.