Why is a git merge required if I want to amend last remote commit? -


sometime commit or push code , realize there's tiny error somewhere. 'amend last commit' new changes, , happens when try push:

if haven't pushed last commit, works fine

if pushed last commit,

$ git push origin https://github.com/kyklos-italy/gitfashion.git  ! [rejected]        develop -> develop (non-fast-forward) error: failed push refs 'https://github.com/kyklos-italy/gitfashion.git' hint: updates rejected because tip of current branch behind hint: remote counterpart. integrate remote changes (e.g. hint: 'git pull ...') before pushing again. hint: see 'note fast-forwards' in 'git push --help' details. 

so merge getting

$ git pull origin merge made 'recursive' strategy. 

and i'm allowed push.

why there such behaviour?

amending creates new commit. means, have merge local, generated, branch remote changes.

for example have commits:

a---b---c  

when amend these changes afterwards, c original , d amended commit:

a---b---d      \       c 

as long there no other branch pointing c, won't see anymore , looks nothing has changed editions (when pushed, remote branch still should point c, e.g. origin/master). because there new branch now, have merge these.

maybe, avoid merging pushing option --force. given have required privileges:

git push origin master --force 

Comments