Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push failed after 'git reset --hard HEAD~1' of local repo [duplicate]

Tags:

git

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?

like image 794
John Dibling Avatar asked Jul 13 '12 15:07

John Dibling


People also ask

Do we need to commit after git reset hard?

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.

How do I restore git After resetting hard?

We can use the command git fsck to recover the files after a hard reset.

How do I reset my git repository locally?

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> .

What does git reset -- hard head do?

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.


1 Answers

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.

like image 111
jli Avatar answered Oct 13 '22 01:10

jli