Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push error: "! [rejected] develop -> develop (non-fast-forward)"

Tags:

git

bitbucket

I have a list of commits (newest first):

abcd4 message
abcd3 wrong commit message2
abcd2 wrong commit message1
abcd1 message

I need to change commit messages of abcd2 and abcd3. I'm doing it the following way:

rebase -i abcd1

Then, in interactive mode I replace pick with reword, change the necessary commit messages and save the changes. Everything works fine here.

The problem is the following: the branch is fully pushed to Bitbucket so there are wrong commit messages on Bitbucket as well.

I tried to push the changes but got the error:

 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://[email protected]/user/repository.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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried to pull the changes but got smth. weird after pull was accomplished:

git log --pretty=format:'%h %s' --graph
*   ccceeefff Merge branch 'develop' of https://bitbucket.org/user/repository into develop
|\  
| * abcd3 wrong commit message2
| * abcd2 wrong commit message1
* | new_hash_of_abcd3 new commit message2
* | new_hash_of_abcd2 new commit message1
|/  
* abcd1 message

So my question is: what is the correct way to change the messages in my case?

like image 888
Sray Avatar asked Jun 25 '14 17:06

Sray


People also ask

How resolve git push rejected non-fast-forward?

If you do a commit in one project and then accidentally push this commit, with bypassing code review, to another project, this will fail with the error message 'non-fast forward'. To fix the problem you should check the push specification and verify that you are pushing the commit to the correct project.

Why is my git push being rejected?

A commit gets rejected and causes a failed to push some refs to error because the remote branch contains code that you do not have locally. What this means is that your local git repository is not compatible with the remote origin.

What does a non-Fast-Forward Error git push reject mean what is the most common way of dealing with this?

Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.

What is non-Fast-forward?

A non-fast-forward merge is a merge where the main branch had intervening changes between the branch point and the merge back to the main branch. In this case, a user can simulate a fast-forward by rebasing rather than merging. Rebasing works by abandoning some commits and creating new ones.


1 Answers

You should be able to force the push with (assuming you have bitbucket set up as the remote "origin"):

git checkout develop
git push -f origin develop

Note that before you do that you may need to reset your local develop branch (if it's now pointing at your pulled/merged commit):

git checkout develop
git reset --hard new_hash_of_abcd3
git push -f origin develop
like image 113
jkyako Avatar answered Nov 13 '22 23:11

jkyako