How to roll back a single file accidentally deleted in git
PHPz2017-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?
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
It’s very simple, you know which submission it is in, just use it
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 $filename
git log $filename
重置文件
git reset $commit_id
恢复文件
git checkout $filename
Reset filegit 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