Search code examples
gitgitlabgit-commitgit-pushgit-revert

Changes in local file lost due to it synching with out of date remote git repository


I tried to push a commit to my gitlab repo through the following commands (I'll describe output as I go):
git checkout origin no branch called origin
git checkout -b origin
git status
git add README.md
git add src/example.ipynb
git add src/.ipynb_checkpoints/
git commit -m notebook update
git push origin master this is where I realized I was probably on detached head and switched to master
git checkout master
git status still not showing changes
git log -1
git checkout master
git reset --hard 44263cc6fd2bd60be54da344a6d344eb3c42a03a
git push origin master

When I noticed my local notebook file reverted back to an old version I tried to revert that last published commit by doing
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all
git revert 407302e

Then I got the following error from running git revert:

error: your local changes would be overwritten by revert.
hint: commit your changes or stash them to proceed.
fatal: revert failed

So as you can see a series of bad decisions got me here, how do I recover the changes in my file? Thanks


Solution

  • I solved it partly thanks to GitKraken. Even though it was still impossible to revert the commit to due a merge conflict, it still allowed me to view the differences between the new and the old file which I pretty sure is achievable through commands as well but is a lot of work for a git noob like me.