'How to find lost git commits after push?
I downloaded a ZIP file of a project commit. After making some changes, I ran the commands:
git init
git branch -m main
git remote add origin <url>
git add .
git commit -m "message"
git push -f origin main
After running these commands, all commits that were made before were deleted and this was the only commit in the branch. I tried running
git fsck --unreachable
git log
git reflog
but I couldn't find the lost commits
Solution 1:[1]
For anyone having similar problems, if you download a ZIP file of a repository, it doesn't include the git history. Because of that, when you push your changes, there is no history of any commits before that. If you or a colleague have another version with the history, you can simply push that. If not, the best approach is to contact the Github support and ask them for help as they keep all the commits so they can probably restore it for you but I haven't personally tested this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Luka Kreši? |