时隔一个星期, 当我再次完成开发之后, 准备将代码上传, 却出现了一个上传代码的错误, 记录一下错误和解决方案
解决方案:
git fsck --full
(base) ifeng@ubuntu:~/Desktop/luffycity$ git fsck --full error: 对象文件 .git/objects/c9/e590416bbe286dc32a17ddf14670ebb52e4520 为空 error: 对象文件 .git/objects/c9/e590416bbe286dc32a17ddf14670ebb52e4520 为空 fatal: 松散对象 c9e590416bbe286dc32a17ddf14670ebb52e4520(保存在 .git/objects/c9/e590416bbe286dc32a17ddf14670ebb52e4520)已损坏
(base) ifeng@ubuntu:~/Desktop/luffycity$ cd .git (base) ifeng@ubuntu:~/Desktop/luffycity/.git$ find . -type f -empty -delete -print ./FETCH_HEAD ./objects/cd/cd1a2512ad47d7e2290b02a2a77ea79277e7c9 ./objects/c9/e590416bbe286dc32a17ddf14670ebb52e4520 ./objects/6a/871d8bf9b841b8febcc3a4c7c6c17ac9557a79 ./objects/82/01d128f3356e1cbe2c2413ff422c53974b80db ./objects/2c/cdc2e45330ea23f1fb2f1cf133c7e9dc54680b ./objects/2c/65cffca3b6403b675f19701f41e64f3166401f ./objects/71/420f984a2d039563d7b80cb295f37e55b45ad3
git fsck --full
, 还是有错,head指向元素不存在,是之前一个空文件,我们已经删了(base) ifeng@ubuntu:~/Desktop/luffycity/.git$ git fsck --full 正在检查对象目录: 100% (256/256), 完成. error: refs/heads/feature/user:无效的 sha1 指针 c9e590416bbe286dc32a17ddf14670ebb52e4520 error: refs/remotes/origin/feature/user:无效的 sha1 指针 c9e590416bbe286dc32a17ddf14670ebb52e4520 error: HEAD:无效的 sha1 指针 c9e590416bbe286dc32a17ddf14670ebb52e4520 error: 71420f984a2d039563d7b80cb295f37e55b45ad3:cache-tree 中无效的 sha1 指针 悬空 blob 38fae659ca427cf6d82705f281bd6549bb3bef41 悬空 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 悬空 blob a517beeb35b0c70cd4b361ec6e085e58ef47c225
tail -n 2 .git/logs/refs/heads/feature/user
, 后面的部分就是上面信息的路径(base) ifeng@ubuntu:~/Desktop/luffycity$ tail -n 2 .git/logs/refs/heads/feature/user 03f77f97f3f2f687186f74b7ceaee4e9c6103dde 377adde104760d582bf76985a95f5c2262491b1c ifeng <ifeng190410@gmail.com> 1684228848 +0800 commit: feature: 注册功能实现流程-客户端请求发送短信并实现短信倒计时冷却提示!
git show 377adde104760d582bf76985a95f5c2262491b1c
(base) ifeng@ubuntu:~/Desktop/luffycity$ git show 377adde104760d582bf76985a95f5c2262491b1c
可以看到内容是正常的
那么我们就重新设置head, 使其指向倒数第二条git update-ref HEAD 377adde104760d582bf76985a95f5c2262491b1c
最后我们git push的时候发现还是有错
(base) ifeng@ubuntu:~/Desktop/luffycity$ git push origin feature/user error: refs/remotes/origin/feature/user 没有指向一个有效的对象! error: refs/remotes/origin/feature/user 没有指向一个有效的对象! To gitee.com:i__feng/luffycity.git ! [rejected] feature/user -> feature/user (fetch first) error: 无法推送一些引用到 'git@gitee.com:i__feng/luffycity.git' 提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外 提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更 提示:(如 'git pull ...')。 提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
根据错误提示执行git pull origin feature/user
我们从远程仓库自动合并feature/user
(base) ifeng@ubuntu:~/Desktop/luffycity$ git pull origin feature/user 来自 gitee.com:i__feng/luffycity * branch feature/user -> FETCH_HEAD 自动合并 luffycityapi/luffycityapi/apps/users/serializers.py Merge made by the 'recursive' strategy.
(base) ifeng@ubuntu:~/Desktop/luffycity$ git push origin feature/user 枚举对象中: 28, 完成. 对象计数中: 100% (27/27), 完成. 使用 4 个线程进行压缩 压缩对象中: 100% (13/13), 完成. 写入对象中: 100% (14/14), 2.16 KiB | 736.00 KiB/s, 完成. 总共 14 (差异 6),复用 0 (差异 0) remote: Powered by GITEE.COM [GNK-6.4] To gitee.com:i__feng/luffycity.git c9e5904..ff1c1a9 feature/user -> feature/user