Undo deleted files in git?

前端 未结 3 822
盖世英雄少女心
盖世英雄少女心 2021-01-24 18:37

Newbie needs some help undoing a mess!

I was tring to push my site to a git repository, so I used the git add command. Then, before I did the commit, I realized I had a

相关标签:
3条回答
  • 2021-01-24 19:30

    have you tried git reset --hard (commit # before this horrible accident)?

    then use git pull origin master to extract files from the online git repo to get your files back.

    A more in depth explanation of this process is located on this SO thread.

    0 讨论(0)
  • 2021-01-24 19:36

    If you already deleted all files in your workspace. You can get it back by using the following command.

    git checkout -f
    

    The files should be back!

    0 讨论(0)
  • 2021-01-24 19:37

    You can do

    git reset --hard HEAD^
    

    To move one step back in the version history, effectively undoing the last commit including all deletes.

    If you have already pushed your changes you can instead do

    git revert HEAD
    

    To create a new commit reverting the delete commit, and then push that.

    This answer assumes that you did commit the changes, and that was the last commit you did. If you didn't commit the changes, Willy's answer is better.

    0 讨论(0)
提交回复
热议问题