commit - git I forgot to edit a line before commiting and pushing -


i decided integrate library code. add library, , change couple lines of code start implementing it. compiles, commit , push repo.

i realise later i've missed line still on old code. give google search , find out git commit --amend, , lucky me, there no other commits. thought had fix line of code, git add file, git commit --amend, , git push repo, git tells me

! [rejected] master -> master (non-fast-forward) hint: updates rejected because tip of current branch behind

i find strange since i'm on latest commit , if git reset -soft head~1 being aligned repo, besides single line of code i've changed.

am doing wrong? don't want make entirely new commit single line of code should've been part of last commit.

if want amend commit, need force branch remote:

git push origin master --force 

keep in mind overwrite remote branch, might potentially cause havoc else sharing branch.

also, need ascertain no new commits added remote branch since commit trying amend. forcing branch out clobber new work other made after commit in question.

as can tell, there many things go wrong here. safer strategy, , recommend you, fix missing line of code in new commit , push changes out remote.

update:

the reason getting updates rejected because tip of current branch behind error because amending commit on head of local branch caused local branch diverge remote. here diagram showing local , remote master branches looked before amend:

remote: -- b -- c local:  -- b -- c 

in other words, date. however, when amended commit c locally, replaced new commit (with new sha-1 hash). here diagram looked after amend:

remote: -- b -- c local:  -- b -- c' 

when tried pushing, git thought commit b common ancestor, , behind remote master. way of drawing is:

remote: -- b -- c local:         \_ c' 

git doesn't realize intend amended commit replace c on remote, have force push achieve this.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -