简体   繁体   中英

Restore Git Files Between last Commit and Current after rm

I added and deleted some files after my last commit. I delted the whole subfolder accidentially. The order of git commands:

git add src/app/klicka/*

modified:   src/app/klicka/_klicka.scss
new file:   src/app/klicka/img/beispiel-buttons.png
new file:   src/app/klicka/img/beispiel-lightbox-1.png
new file:   src/app/klicka/img/beispiel-lightbox-2.png
new file:   src/app/klicka/img/beispiel-lightbox-3.png
new file:   src/app/klicka/img/beispiel-pascoe.png
new file:   src/app/klicka/img/button-jetzt-ausprobieren.png
new file:   src/app/klicka/img/referenzen-row-1.jpg
new file:   src/app/klicka/img/referenzen-row-2.jpg
new file:   src/app/klicka/img/referenzen-row-3.jpg

but there where still the deleted files

so I did:

git rm */klicka/* $(git ls-files --deleted) which I got from here: Removing multiple files from a Git repo that have already been deleted from disk but it seems you can't use it on a subpattern, so it removed my whole folder.

After that I used git reset because I wanted to unstage all changes. But now the folder is still gone. I did not commit is there a way to get back the status between the rm and the last commit? I still have other commits to do.

You can use git reflog command, which gives HEAD list of commands execute by you. You can go back to the HEAD when you executed the command, everything will be back.

$ git reflog

Following will be the output

git reflog输出

Now to go back to that HEAD, you can run below command suppose you want HEAD@{5} to be applied.

$ git reflog HEAD@{5}

You can get more info here http://git-scm.com/docs/git-reflog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM