D
D
dmptts2018-05-16 22:00:14
git
dmptts, 2018-05-16 22:00:14

How to recover deleted files after significant changes with git?

Good afternoon!
A fork of the git repository was made, a sufficiently large number of files were deleted in the local copy of the fork, after which n number of commits were pushed to the remote fork. Is there any way to recover deleted files by saving the changes made? Pulling the master repository from which the fork was made to the local repo again fails, probably because there were no changes in the master repository and git thinks that everything is up to date.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill, 2018-05-16
@dmptts

Do git reset HEAD~1, where 1 is the number of commits in which files were removed. Then carefully remove the deleted files from the staging area and push all the changes back into place.

D
Dmitry, 2018-05-28
@dlnsk

First, find a commit that still has files (in your case, you can use upstream/master). Then:
1. Visualize the list of changed files (we filter only deleted ones with grep)
2. Restore the necessary files from the commit
Next, make a new commit, push to the repository, etc.

git diff --name-status upstream/master | grep ^D
git checkout upstream/master <path/to/the/deleted/file>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question