博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
恢复corrupted git-svn repository的过程记录
阅读量:4350 次
发布时间:2019-06-07

本文共 2021 字,大约阅读时间需要 6 分钟。

问题

由于主机异常宕机导致git中的文件变成了0字节的,执行git相关的命令报错。

fatal: object 016660b7605cfc2da85f631bbe809f7cb7962608 is corrupted

 

恢复过程

# 从镜像clone中恢复一个git repo,幸好有一个mirror clone。

git clone --mirror billing@10.164.129.25:/billing/git/cmcc.git /srv/git/cmcc1.git

# 把损坏的git repo中与SVN相关的内容复制到新的git repo中。

cp -R cmcc.bad.git/config cmcc1.git/ cp -R cmcc.bad.git/svn cmcc1.git/ cp -R cmcc.bad.git/logs cmcc1.git/ ... cp -R  cmcc.bad.git/info/refs cmcc1.git/info/ cp -R cmcc.bad.git/refs/heads/master cmcc1.git/refs/heads/

# 根据git log中的信息对新git repo中的相关文件中的hash做了些调整

# 尝试执行/usr/bin/git --git-dir=/srv/git/cmcc1.git svn fetch 仍然报错

唯一没法调整的文件是svn/refs/heads/master/.rev_map.21a24a4a-c245-7e45-a0a4-218b2805dfce,这个不是文本的。

幸运的是从网上搜到了一个生成rev_map文件的脚本

1: #! /usr/bin/env gawk -f
2: # git --no-pager log | gawk -f this-script > revmap.txt
3: # xxd -c 24 -r revmap.txt \
4: #    .git/svn/refs/remotes/trunk/.rev_map.cfe28804-0f27-0410-a406-dd0f0b0b656f
5: # 0000000: 0000 0001 cce6 285e 48e1 e3cc 0d7d 0617 beb0 4e88 a126 8634
6: # 0000018: 0000 0006 6e4f ada4 bed4 6660 c987 dc74 1243 8973 16cc c810
7: BEGIN {
8:     FS=" "
9:     # this number comes from ``git --no-pager log | grep ^commit | wc -l``
10:     # and is ZERO-indexed because the last xxd will begin with 0000
11:     # you might be tempted to think it is the highest r-number, but no,
12:     # because evidently not every subversion commit made it to git
13:     cnt=30554
14: }
15: /^commit / {
16:     cmit=$2
17: }
18: /git-svn/ {
19:     # remove everything except the r-number
20:     sub(/[^@]+@/,"")
21:     # remove the repository-id
22:     sub(/ .*$/,"")
23:     addr=cnt * 24
24:     # thankfully, xxd is tolerant of not having
25:     # any spaces, so we can just dump the commitish
26:     # right into the file
27:     printf "%08x: %08x%s  \n", addr, $0, cmit
28:     cnt = cnt - 1
29: }

删除现有的rev_map文件,按照上面的说明重新生成了一个。

执行 /usr/bin/git --git-dir=/srv/git/cmcc1.git svn fetch 成功。

 

操作过程经过很多失败的尝试,记录不是很完整,仅作参考。

转载于:https://www.cnblogs.com/luojunqiang/archive/2012/09/14/2685416.html

你可能感兴趣的文章
技术分析淘宝的超卖宝贝
查看>>
Azure云服务托管恶意软件
查看>>
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>
生产订单“生产线别”带入生产入库单
查看>>
crontab导致磁盘空间满问题的解决
查看>>
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
初识前端作业1
查看>>
ffmpeg格式转换命令
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>
JAVA 基础 / 第八课:面向对象 / JAVA类的方法与实例方法
查看>>