Small team. A colleague pushed to
$ git push origin 2860a4c:master
! [rejected] 2860a4c -> master (non-fast-forward)
error: failed to push some refs to 'firstname.lastname@example.org:example/myproj.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
reset hard 2860a4c
push -f origin
Below are the steps you may do, assuming you have permission for
git push -f.
On your machine, do:
# Step 1: Take the changes from remote git pull # Step 2: Note the commit to which you want for restoring your repo to # using `git log`. Say the commit id is "x". git log # Step 3: Do hard reset for that commit. All the changes after commit "x" will be gone git reset --hard x # where x is the commit id # Step 4: Push to remote git push -f
Then on collegue's machine, do
step 1 to
step 3 and then do
git pull to merge the remote changes
In case you do NOT have permission for
git push -f, do:
git pull git revert <commit id> # may get it via "git log" git push
git revert, changes from the reverted commit will be removed, but this commit will remain in the commit history.