I am trying to recover changes that were made to a file using git.
I used reset --hard
on my branch which lost a bunch of commits, and these commits contained changes to a text file.
I understand there are functions like reflog
in git that can be used to get the hash of commits you thought were lost. In my case, the commits I am trying to recover were from about 3 weeks ago so I am worried that I won't be able to get them back.
Is it possible for me to somehow recover the changes that were made to this file?
CodePudding user response:
You could try the following:
git reflog --pretty=oneline --date=short --before=2022-01-09
--pretty=oneline --date=short
will add the date to the output and it should make it easier to look through the output--before
should make it easier to only look through relevant days
- Find the entry that looks like it could have your lost work
git checkout -b my_lost_work
(orgit switch -c my_lost_work
) - create a branch with lost workgit push