時隔一個星期, 當我再次完成開發之後, 準備將程式碼上傳, 卻出現了一個上傳程式碼的錯誤, 記錄一下錯誤和解決方案
解決方案:
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 <[email protected]> 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: 無法推播一些參照到 '[email protected]: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
本文來自部落格園,作者:{Max},僅供學習和參考