3 回答

TA貢獻1871條經驗 獲得超13個贊
Git通常不會丟棄任何東西,但是從中恢復可能仍然很棘手。
如果您有正確的來源,則可以使用該--force
選項將其推入遙控器。除非您告知,否則Git不會刪除任何分支。如果您實際上丟失了提交,請查看此有關恢復提交的有用指南。如果您知道想要的提交的SHA-1,那么可能就可以了。
最好的事情:備份所有內容,然后查看本地存儲庫中仍然存在的內容。如果可能,在遙控器上執行相同的操作。使用git fsck
,看看你是否能恢復的東西,最重要的不運行git gc
。
最重要的是,--force
除非您真的很認真,否則不要使用該選項。

TA貢獻1796條經驗 獲得超4個贊
解決方案已經在這里提到
# work on local master
git checkout master
# reset to the previous state of origin/master, as recorded by reflog
git reset --hard origin/master@{1}
# at this point verify that this is indeed the desired commit.
# (if necessary, use git reflog to find the right one, and
# git reset --hard to that one)
# finally, push the master branch (and only the master branch) to the server
git push -f origin master
- 3 回答
- 0 關注
- 610 瀏覽
添加回答
舉報