let say I have made some files and committed them in git modified it and then again committed it. but now someone has access to the files and done total destruction like deleting some files renamed some files and then commited to git. Now I want to get to my old files that have been committed. how to do it?
2 Answers
If you want to roll back your repository to specific commit
git reset --hard commit_hash 2 Comments
git push origin branch_name --forceIf 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.