Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to recover deleted & committed files from the remote repository?

Mike Braca July 27, 2020

A coworker deleted some files and committed them. Without paying too much attention, I pulled his changes and committed them. 16 of the files he deleted should not have been and now neither of us has a copy of them.

I figured this was no problem, I will simply reset each of the files to their last commit. As I understand it, the procedure is to go to the commit where the files were deleted, then right-click on each file and select menu item "Log Selected..." which will point me at the desired commit. But when I select one of the files and right-click on it, the "Log Selected..." menu item is dim! It seems to be dim for all of the deleted files, but is OK for the files that were just changed.

What am I missing? I would hate to have to look through a ton of commits to find each of the 16 files!!! Help! The Sourcetree version is 3.3.8.

LogSelectedIsDIm.png

1 answer

1 accepted

0 votes
Answer accepted
prashant_gami
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 27, 2020

If the commit only has file deletion, you can reverse commit it, it's easier.

Go to commit, Right click, and then reverse commit.

Or you can "Reset to commit" to a previous commit and then cherry pick commits that you want there.

 

PS: you will have to force push if you choose reset to commit as you are overriding the history. So make sure you cherry pick all the stuff that you actually want or else will be overwritten by push.

 

The menu you are showing seems bit off with few options disabled. Can you give more details?

Mike Braca July 30, 2020

Hi Prashant, sorry for not responding sooner, but we did manage to find a recent version of the files so were able to restore them that way.

I was reluctant to try the Reset to commit option because I didn't know Git well enough to understand all the ramifications.

I didn't think of doing the "Reverse commit" on the entire commit. There were a bunch other files changed, but it would have been relatively easy to discard those changes before committing the reversal.

As it was, I was trying to just reverse the commit for each of the erroneously deleted files, as was suggested by a post from 2015 on this forum), but was stymied by the "log selected" menu item being dim for the individual deleted files (it was available for the changed files in that commit). I agree that it looks "off" and seems like a bug because reversing the removal of a file is easily reversible!

To recap what that post said to do:

1. Go to the commit that deleted the files.
2. Right-click on the deleted file and select "Log Selected" menu item.
3. Determine when the file was last committed.
4. Go to that commit
5. Right-click on the deleted file and select "Reset to commit" menu item.

Seems like it's a Sourcetree bug that "log selected" is dim in step 2.

Mike P February 28, 2024

>Seems like it's a Sourcetree bug that "log selected" is dim in step 2.

absolutely.  reversing the entire commit is very invasive.  I want to restore just one file from the commit.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events