Anuj Shrestha Anuj Shrestha - 23 days ago 4
Git Question

Revert all the changes through the Git verson control

let say i have made some files and commited them in git modified it and then again commited it. but now someone has acess to the files and done total distruction like deleting some files renamed some files and then commited to git. Now i want to get to my old files that have been commited. how to do it?


If you are in "dev" mode, meaning you are in front of your IDE wanting to have a look at those deleted files, then one thing you can try is to simply checkout an older commit when those files were still active in the branch:

git checkout branch
git log
# find the SHA-1 hash of the commit you made containing the files
# now checkout that commit in the detached HEAD state
git checkout <SHA-1>

Like magic, the missing files should now be visible in your IDE. You can review them as you need, and then return to the branch via:

git checkout branch

If you decide you want to resurrect a file which has been deleted, but which used to be present, then you do so via:

git checkout <SHA-1> path/to/your/deleted/file

where SHA-1 is the hash of the commit where the file was still extant. This way, you can safely bring back deleted files, and commit them again.