Home > Blockchain >  Lost local files after git pull --rebase origin [branch]
Lost local files after git pull --rebase origin [branch]

Time:11-29

  • Was trying to deploy my vue/vite project onto github pages and use a custom domain, but ran into some issues and messed things up by using git commands I didn't fully understand
  • The deployed project worked before I tried adding a custom domain
  • Followed instructions from the following video to deploy a vite project onto github pages: https://youtu.be/yo2bMGnIKE8
  • Followed instructions from here to add custom namecheap domain: https://youtu.be/2K7asqt8wMw
  1. npm run build,
  2. git add dist -f
  3. git commit -m "adding dist"
  4. git subtree push --prefix dist origin gh-pages // [rejected] error: failed to push some refs to 'url', hint: Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g.,) 'git pull ...') before pushing again.
  5. git pull
  6. git subtree push --prefix dist origin gh-pages // [rejected] error: failed to push some refs to 'url', hint: Updates were rejected because a pushed branch tip is behind its remote counterpart. Check out this branch and integrate the remote changes (e.g. 'git pull ...') before pushing again.
  7. git status: On branch main, Your branch is ahead of 'origin/main' by 11 commits. (use "git push" to publish your local commits)
  8. git push
  9. git status: Your branch is up to date with 'origin/main.'
  10. git subtree push --prefix dist origin gh-pages // [rejected] error: failed to push some refs to 'url', hint: Updates were rejected because a pushed branch tip is behind its remote counterpart. Check out this branch and integrate the remote changes (e.g. 'git pull ...') before pushing again.
  11. git pull origin main
  12. git pull origin gh-pages
  13. git pull --rebase origin gh-pages // lost all of my local files and reverted to initial project scaffolding from vue/vite
  14. Now I'm here panicking and still without a deployed project :)

link to github: https://github.com/AnthonyVNgo/LearnFS

Tried a bunch of git commands and followed the hint responses, but dug myself into a deeper hole.

CodePudding user response:

To recover lost work you can:

  1. Run git reflog
  2. Find the entry that looks like it could have your lost work
  3. Run git checkout the_id_shown_in_git_reflog e.g. git checkout 100e500bd.
  4. Confirm that the lost work is found. If not, repeat git reflow -> git checkout until you find your work.
  5. git checkout -b my_lost_work - create a branch with lost work
  6. git push
  7. Relax. Now all your work is safely in github in a separate branch and you can start formulating a plan to fix your main and gh-pages branches.

CodePudding user response:

Check if your work has been stashed away :

git stash show
git stash list
  • Related