python - 如何将文件的所有 git 版本保存到磁盘?
问题描述
在 git 中有一个file.py
which 有三个版本和三个唯一的提交哈希。
那么如何以编程方式将所有版本恢复到特定文件中,例如:
0_<git_hash>_file.py
1_<git_hash>_file.py
2_<git_hash>_file.py
解决方案不一定是 Python,但git
目前正在查看 Python 包。
解决方案
n=0
git log --pretty= --diff-filter=d --raw -- $file |
while read m1 m2 h1 h2 rest; do
eval git show $h2 > $((n++))_${h2}.$file
done
或者
n=0
git log --pretty=%h --diff-filter=d -- $file |
while read; do
eval git show $REPLY:$file > $((n++))_$REPLY.$file
done
取决于您是否希望在结果文件名中包含 blob 或提交的哈希。
推荐阅读
- r - Outlook 附件保存脚本在 Windows 命令提示符下不起作用(在 RStudio 中完美运行)
- sql - 实时更新的仪表板,如何构建
- c# - AvalonEdit 如何在转换器中添加新语法
- java - Apache POI SAX XSSFReader 读取错误的日期格式
- apache - 有没有办法在 Apache HTTP Server 中实现 HTTP/3 (QUIC)?
- html - 部分标签中的列彼此堆叠而不是彼此相邻
- memory-leaks - BottomSheetDialogFragment 在 LeakCanary 2 中显示内存泄漏,但我不确定为什么?
- jenkins - 詹金斯插件
- ruby-on-rails - 需要在 factory 中指定 id 以进行关联
- postgresql - Postgresql SQL 抛出不明确的列错误