How to roll back a single file accidentally deleted in git
PHPz
PHPz 2017-05-02 09:51:46
0
5
1176

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?

PHPz
PHPz

学习是最好的投资!

reply all(5)
黄舟

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.

大家讲道理

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

左手右手慢动作

git stash pop can also be tried

某草草

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🎜
習慣沉默

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template