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?

1

2 Answers 2

1

If you want to roll back your repository to specific commit

git reset --hard commit_hash 
Sign up to request clarification or add additional context in comments.

2 Comments

it says head deattached and when i try to push to git hub it again push the same modified and deleted file help plz
@AnujShrestha : git push origin branch_name --force
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.