git reflog shows all activity, even squashed commits, etc. (correct me if I am wrong).
Is there a git CLI command to backup git reflog?
Obviously if I delete the local version of a repo I have lost my reflog (correct me if I am wrong).
I wondered if I can git push it for safety or something like that?
If not what approach should I take to prevent loss of reflog?
Update: in response to Jiri Kremser, if I backup .git/logs can I git reset --hard to any commit in the reflog after I have restored it?
Yes and no. There is no command for it, but you can make the backup of .git/logs where the reflog is stored.
However, only the references to commits are stored there, so it's like making backup of symbolic links (or shortcuts in Windows). It may work, depending on what you want to do.
In general, it's not a good idea to make the reflog public, because it was meant to be for local repo only.
You can think of the reflog kind of like an audit trail for all of the things you've done with your Git repository. It's immediately useful if you need to go back and restore something that was lost via some process, but backing it up in the long run won't accomplish all that much.
The more valuable thing to back up would be the actual repository. Losing those actual, concrete changes to your Git repository would absolutely cause data loss, whereas losing the reflog would generally mean you can't look at the list of commands and figure out where a rebase started. While that's infinitely useful when you've got a stable environment, if you need to restore it for any reason, you genuinely should care more about the overall repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With