[英]Git + Rails: How to restore files deleted with “git rm -r”?
我用git rm -r刪除了rails應用程序中的db文件夾
我試過了
git reset HEAD
和
git reset --hard HEAD
但是遷移文件沒有回來。 我嘗試提交,然后運行重置,但仍然沒有。
我該怎么辦?
您可以從仍然存在的提交中簽出文件。 這是怎么做的。
git checkout <commit where the file still exists> -- db
# Example:
git checkout 6936142 -- db
# This also works, but if you have a branch named the same as the file or path,
# it will throw an error.
git checkout 6936142 db
嘗試git reset --hard HEAD^1
(HEAD之前的提交)。 或者您可以使用git log
獲取先前已知工作提交的哈希值,然后使用git reset --hard <hash>
。
您可以從上次提交或索引中簽出單個文件。
git checkout db/*
從索引中git checkout db/*
下的所有內容
git checkout master db/*
從master分支的頭部git checkout master db/*
下的所有內容
你可能能夠以這種方式挽救你的大部分東西
閱讀更多: git help checkout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.