简体   繁体   English

如何保护大量孤立的 Git 提交?

[英]How can I protect a large number of orphaned Git commits?

I am using Git to keep track of machine learning experiments.我正在使用 Git 来跟踪机器学习实验。 My workflow is to save the Git hash with the experiment results, so I have a pointer to the exact code that produced those results.我的工作流程是将 Git hash 与实验结果一起保存,所以我有一个指向产生这些结果的确切代码的指针。 The problem is that almost none of the commits associated with experiments will end up in a real branch, since most ideas turn out not to work well.问题是几乎没有一个与实验相关的提交最终会在一个真正的分支中结束,因为大多数想法都不能很好地工作。 These commits end up orphaned according to Git, but I would like to make sure I can still check out the code for each historical experiment via its Git hash.根据 Git,这些提交最终成为孤立的,但我想确保我仍然可以通过其 Git hash 查看每个历史实验的代码。 These orphaned commits are vulnerable to garbage collection via git prune and possibly other mechanisms.这些孤立的提交很容易通过git prune和可能的其他机制进行垃圾收集。

My question is: how can I make sure orphaned commits are not inadvertently deleted?我的问题是:如何确保孤立的提交不会被无意删除? If it is not possible, are there other Git commands that are dangerous?如果不可能,是否还有其他危险的 Git 命令? I know I can create a branch or tag for each of the orphaned commits, but at this point there are too many to do so manually, and in any case I'd prefer not to clutter my actual branches/tags.我知道我可以为每个孤立的提交创建一个分支或标签,但此时手动执行的操作太多了,无论如何我都不想弄乱我的实际分支/标签。

You can set gc.pruneExpire to never .您可以将gc.pruneExpire设置为never This is indiscriminate and will cause your repository size to bloat.这是不分青红皂白的,会导致您的存储库大小膨胀。

Don't do this.不要这样做。 Use tags .使用标签 I know you don't want to, but relying on orphaned commits is very fragile.我知道你不想这样做,但是依赖孤立的提交是非常脆弱的。 Tagging is simpler, safer, and doesn't bloat your repository.标记更简单、更安全,并且不会使您的存储库膨胀。 Tags can be pushed to a remote repository so you have a backup.标签可以推送到远程存储库,以便您进行备份。

To mitigate clutter give them all a prefix like experiment/1 , experiment/2 .为了减轻混乱,给它们都加上一个前缀,比如experiment/1experiment/2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM