Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

git - ahead by x commits following merge but cannot push

We have a remote repo with different versions v1 through to v4, we have now gone live with v4 and are starting work on v5. 90% of all the code was created in v4. One of our devops cut a new v5 branch from master but it is missing all of v4 code.

I have checked out v5 and did the following command to merge v4 into it.

git merge v4

During which it scrolls through all of the changes we made in v4, so definitely looks good.

if I then do a

git status

it tells me that

    Your branch is ahead of origin/v5 by 44 commits.
    (use "git push" to publish your local commits)

nothing to commit, working tree clean

which seems to contradict itself?

I then attempt to push to v5 with

git push origin HEAD:refs/for/v5

and it returns:

    Total 0 (delta 0), reused 0 (delta 0)
    remote: Processing changes: refs: 1, done

followed by:

! [remote rejected] HEAD -> refs/for/v5 (no new changes)
error: failed to push some refs to '......'

No doubt I'm missing a step or have done something wrong but I can't quite work out what?

question from:https://stackoverflow.com/questions/65641513/ahead-by-x-commits-following-merge-but-cannot-push

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When git is used in conjunction with gerrit then you cannot do a merge exactly as normal as gerrit cannot handle the fact you've fast forwarded and therefore does not see anything new to commit.

To get around this you need to use the "no fast forward" option when merging

    git merge v4 --no-ff

then you commit and push as normal.

Thanks to all who commented.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...