Suppose a person cloned a git repository and deleted the .git folder. Is there a way to recover which commit they were on? This isn't a duplicate of Best way to restore .git folder or Can deleted .git be restored?, because years have past since this event. I'm now trying get it back under git to update it to a new version. However, changes may have been introduced in those years, that I need to merge/rebase onto the new version.
My current idea is to:
git clone --bare
git config --local --bool core.bare false
Is there a better way? There's a semver, but it wasn't updated very much so it only cuts down the range to around a year or two. I don't believe the repository was changed much, so I'd guess there are exact matching files. Maybe I could use that information to narrow down the possible commits? Thanks!
I would do:
commit the actual sources into some branch (e.g. _tmp_
), so that index is clean
iterate over all possible commits (e.g. git rev-list master
) and check the diff
git rev-list master | while read rev; do
git diff "$rev" "_tmp" && echo "it is $rev!"
done
When _tmp_
contains files which are untracked in the repository, the git diff
will never succeeded and you have to analyze the diffs (e.g. this with lowest wc -l
wins).