簡體   English   中英

如何將未提交的已刪除文件(用純rm刪除)還原到最后的git commit

[英]how to revert uncommited deleted files (deleted with plain rm) to the last git commit

我錯誤地在git倉庫中rm -rf一個目錄。 更改未提交,我想還原此更改並返回到我的上一個git commit。

# On branch release-1
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    dir/file1
#       [....]

由於文件被刪除,所以我可以執行git checkout -- <file>所以我也可以執行git checkout --但這是行不通的。

因此,我采取了一條捷徑:隱藏變更

$  git stash
Saved working directory and index state WIP on release-1: d2dbff3 removed the CVS $Id lines
Checking out files: 100% (394/394), done.
HEAD is now at d2dbff3 removed the CVS $Id lines

現在一切正常。

我的印象是隱藏是一種蠻力的方法。 是否可以checkout當前分支(整個分支而不給出任何文件)而放棄任何更改?

在短期內,您可以使用git stash dropgit stash drop多余的條目。 將來,您可以使用git checkout HEAD -- dir獲取git checkout HEAD -- dir的head commit版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM