search

Home  >  Q&A  >  body text

How to roll back a single file accidentally deleted in git

I deleted a file by mistake in the company and submitted it to the remote repository. Now I want to get the file back without changing other changes. What can I do?

PHPzPHPz2821 days ago1195

reply all(5)I'll reply

  • 黄舟

    黄舟2017-05-02 09:53:46

    It’s very simple, you know which submission it is in, just use it

    git checkout xxxxx lost_file

    That’s it. Here xxxx is the sha-1 number in the git library.

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-02 09:53:46

    Switch to the previous commit, copy the accidentally deleted file, then create a new branch and paste the commit.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-02 09:53:46

    git stash pop can also be tried

    reply
    0
  • 某草草

    某草草2017-05-02 09:53:46

    View commit_id
    git log $filenamegit log $filename
    重置文件
    git reset $commit_id
    恢复文件
    git checkout $filenameReset file

    git reset $commit_id 🎜Restore file🎜git checkout $filename🎜

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-02 09:53:46

    You can retrieve the lost file by deleting the previous submission ID of the file locally or get it back from the remote end, then add, commit, and push to the remote end again, which means that one more submission and push will be generated, and getting the file back is just one step. Louda's answer, git checkout commit id -- delete file path

    reply
    0
  • Cancelreply