2017-07-24 29 views
1

我所做的是:在初始化回購中還原git rm -rf。

$ git init 
$ git add . 
# bunch of unwanted files were also added 
$ vim .gitignore 
$ git rm -rf * 
$ git add . 
# but the files were actually deleted from the ./ folder. 

現在我必須在目錄中只的.gitignore病毒碼文件。所有必要的文件都沒有了。

由於在這個崗位How to revert a "git rm -r ."?

提的是git reset HEAD的路要走?

我不知道我應該運行這個命令,因爲我還沒有提交任何提交到現在。

+0

'git reset HEAD'說未知版本 –

+0

'git log'看你init初始化SHA然後'git checkout '? – ItayB

+0

'git log' ==>'fatal:您當前的分支'主'還沒有任何提交 ' –

回答

2

運行git fsck --lost-found

$ mkdir tt 
$ cd tt 
$ git init 
Initialized empty Git repository in ... 
$ echo I am foo > foo 
$ echo I am bar > bar 
$ git add . 
$ git rm -rf * 
rm 'bar' 
rm 'foo' 
$ git fsck --lost-found 
notice: HEAD points to an unborn branch (master) 
Checking object directories: 100% (256/256), done. 
notice: No default references 
dangling blob 2adbcadb36527b3048a96c5bad232f6c9e762524 
dangling blob bea14010b78ced155c64da9a4c2b1a6b0831335e 
$ ls .git/lost-found/other/ 
2adbcadb36527b3048a96c5bad232f6c9e762524 
bea14010b78ced155c64da9a4c2b1a6b0831335e 
$ cat .git/lost-found/other/2adbcadb36527b3048a96c5bad232f6c9e762524 
I am foo 

該文件的都走了,但他們所有的內容恢復,並對其hash-ID基礎的名稱。

+0

無需重新開始一週的工作。 :) 有效。我正在瀏覽.git目錄中的文件,但找不到的文件只出現在'git fsck'命令之後。 –

+0

是的 - 在此之前,這些「晃來晃去的blob」位於.git/objects /目錄中,並且是壓縮的Git-ified形式。 – torek