Undo deleted files in git?

前端 未结 3 821
盖世英雄少女心
盖世英雄少女心 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: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.

提交回复
热议问题