简体   繁体   中英

Recover files from previous git commit after git rm

I'm in a really bad situation. I wrote a lot of scripts for a project and accidentally deleted them.

I have 3 branches: master, Dev, App

I develop on the Dev branch, keep a working copy on master, and write application scripts in App. I merged Dev to master, then merged master to App. But when I did I forgot that I had deleted all my app scripts from master and Dev. So I blindly deleted all of my application scripts in App. Now, I want to go back and get those files.

To go back a commit I used

git revert HEAD~1

I then tried

git rm app_*

to untrack the files. But that deleted them all from my folder. And now I can't find them in any commit. How can I get these files back??

Go to the branch you want to fix.

git checkout App

Find the commit before the files were deleted

git log --stat

Remember that SHA and reset to that SHA.

git reset --hard bada55

Repeat for the other branches. You can see what you did and the SHA of what happened using the git reflog command. Helps find points of time that are not on the current branch history.

git checkout [name of file]

or

git reset head --hard

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