0

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Possible duplicate of [How to revert Git repository to a previous commit?](http://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit) – 1615903 Oct 05 '16 at 10:52

2 Answers2

1

If you want to roll back your repository to specific commit

git reset --hard commit_hash
Shravan40
  • 8,922
  • 6
  • 28
  • 48
0

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360