I have a local git repo on my workstation which I push to a dropbox location so that I can pull it down to my laptop via git pull remote dropbox
.
Yesterday I checked in a change on my workstation, committed it and git push dropbox
'ed it. I did not do a git pull
from my laptop because I suspected that I was going to end up throwing that commit away.
Today I decided to throw that commit away, so on my workstation I did:
git reset --hard HEAD~1
So far, so good. Now I want to push this back up to Dropbox, so that on my laptop I can merge and commit from there. So on my workstation I tried:
git push dropbox
And git complained that:
! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '\My Dropbox\dev\repos\xcast.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
How do I get my worstation and Dropbox back in sync again?
First of all git reset — hard is a very dangerous command because it eliminates all of your noncommitted changes. Be sure to always double check that the output of git status is empty (clean) before you begin using it. Git records the state of the files when you stage them with git add or when you make a commit.
We can use the command git fsck to recover the files after a hard reset.
Find the commit hash of the commit you want to reset to with git log . Perform the local hard reset by running git reset --hard <commit-hash> .
Running git reset --hard ORIG_HEAD will let you go back to where you were, but it will discard your local changes, which you do not want. git reset --merge keeps your local changes.
Force push should work: git push -f dropbox
Git is complaining because your remote still has that extra commit, and thus you are behind it in terms of history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With