gpt4 book ai didi

git - 删除运行 git rm --cached 后无法恢复文件

转载 作者:行者123 更新时间:2023-12-04 19:00:57 28 4
gpt4 key购买 nike

运行 git rm --cached 后,我无法恢复意外删除的文件。我尝试过 git reset hard 和其他几种方法,但没有任何帮助

[ec2-user@ip-10-0-0-190 cgsignlab]$ git rm --cached .
fatal: not removing '.' recursively without -r
You have new mail in /var/spool/mail/ec2-user
[ec2-user@ip-10-0-0-190 cgsignlab]$ git rm --cached . -r
error: 'vendor/apix/log' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/aws/aws-sdk-php' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/guzzlehttp/guzzle' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/guzzlehttp/promises' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/guzzlehttp/psr7' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/nategood/httpful' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/nicolab/php-ftp-client' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/psr/http-message' has staged content different from both the file and the HEAD
(use -f to force removal)
error: 'vendor/psr/log' has staged content different from both the file and the HEAD
(use -f to force removal)
[ec2-user@ip-10-0-0-190 cgsignlab]$ git reset HEAD .
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'


[ec2-user@ip-10-0-0-190 cgsignlab]$ git status
# HEAD detached at 04e2948
nothing to commit, working directory clean
You have mail in /var/spool/mail/ec2-user
[ec2-user@ip-10-0-0-190 cgsignlab]$

这些是我需要恢复任何帮助的文件,非常感谢
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: art.php
# new file: ceil.php
# new file: composer.json
# new file: composer.lock
# new file: metaupdate.php
# new file: movetoreview.php
# new file: orders.php
# new file: shipments.php
# new file: shipments/tracking.csv
# new file: src/CG/Aws/S3/Client.php
# new file: src/CG/OrderDesk/RestApi.php
# new file: src/CG/Orders/Order.php
# new file: src/CG/Orders/OrderDetails.php
# new file: src/CG/Orders/RestApi.php
# new file: src/CG/Orders/ShipMethods.php
# new file: src/CG/PitchPrint/RestApi.php
# new file: src/CG/Shipments/TrackingAdapter.php
# new file: src/CG/SignLab/ImageFormatter.php
# new file: src/CG/SignLab/Products.php
# new file: src/CG/SignLab/Utils.php

需要更多评论所以这不认为这是所有代码但需要发布相关日志
[ec2-user@ip-10-0-0-190 cgsignlab]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: art.php
# new file: ceil.php
# new file: composer.json
# new file: composer.lock
# new file: metaupdate.php
# new file: movetoreview.php
# new file: orders.php
# new file: shipments.php
# new file: shipments/tracking.csv
# new file: src/CG/Aws/S3/Client.php
# new file: src/CG/OrderDesk/RestApi.php
# new file: src/CG/Orders/Order.php
# new file: src/CG/Orders/OrderDetails.php
# new file: src/CG/Orders/RestApi.php
# new file: src/CG/Orders/ShipMethods.php
# new file: src/CG/PitchPrint/RestApi.php
# new file: src/CG/Shipments/TrackingAdapter.php
# new file: src/CG/SignLab/ImageFormatter.php
# new file: src/CG/SignLab/Products.php
# new file: src/CG/SignLab/Utils.php
# new file: vendor/apix/log
# new file: vendor/autoload.php
# new file: vendor/automattic/woocommerce/.editorconfig
# new file: vendor/automattic/woocommerce/.gitignore

# new file: vendor/mtdowling/jmespath.php/tests/compliance/wildcard.json
# new file: vendor/nategood/httpful
# new file: vendor/nicolab/php-ftp-client
# new file: vendor/psr/http-message
# new file: vendor/psr/log
#
[ec2-user@ip-10-0-0-190 cgsignlab]$ git reset HEAD

最佳答案

git fsck在这里可能会有所帮助:

git fsck --unreachable

这应该输出哈希列表(可能比您删除的列表多得多)。然后使用这些哈希来获取它们的内容:
git cat-file -p <hash>

不幸的是,你不会得到文件名,只有它的内容。

关于git - 删除运行 git rm --cached 后无法恢复文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52303331/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com