0

I cannot commit and push to Git.

It says: Rejected - non - fast forward.

I have accidentally click on "Amend - (edit previous commit) button in Eclipse.

What can I do?

Please help. Thanks.

Shazam
  • 105
  • 1
  • 7
  • can you show us the output of `git status` – Ahmed HENTETI Nov 25 '19 at 23:34
  • 2
    Possible duplicate of [What does "Git push non-fast-forward updates were rejected" mean?](https://stackoverflow.com/questions/4684352/what-does-git-push-non-fast-forward-updates-were-rejected-mean) – phd Nov 25 '19 at 23:41
  • https://stackoverflow.com/search?q=%5Bgit%5D+push+rejected+non+fast+forward – phd Nov 25 '19 at 23:41
  • Did you push the previous commit (which was replaced with the new commit created by _Amend_)? If yes, you have to reset to the previous commit and commit the changes as a separate commit first. Then, in both cases, do a pull to rebase your commit on top of the commits made by others in the meantime. – howlger Nov 26 '19 at 08:49

3 Answers3

1

The simplest way to resolve this is by rebasing your change on the origin/master. This should create a new changeset that will only contain the difference that you made.

git rebase origin/master
git commit --amend -m"Update your commit message for the new commit"
git push origin HEAD:master
uncletall
  • 6,609
  • 1
  • 27
  • 52
  • Hi! I am working on a branch. Do I rebase origin/ ? – Shazam Nov 26 '19 at 07:49
  • Yes, that's correct, and the push to the branch as well – uncletall Nov 26 '19 at 07:52
  • Thanks. But I am using eclipse. How do I do it? I have tried using command line but it says Authentication Failed. I have also tried to use GUI pull but it says: Pulling 1 repository Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing unknown b28c776928d641cca3586366ddef6f3044d84721 – Shazam Nov 26 '19 at 08:08
  • Assuming the rebase was successful you can use eclipse to push. – uncletall Nov 26 '19 at 08:30
0

You can solve this issue with a

git pull before you push

Actually this issue shows that there have been any other different commits pushed to the remote repository, fast-forward means that the commits can be applied directly on top of the working tree without requiring a merge.

0

You must grab the latest change from the remote before you can push yours.

try this pull without rebase first and see if it's working

    git pull origin master

In case it doesn't work pull again with --rebase

    git pull --rebase origin master

After that create a new commit

    git commit --COMMIT

Then do a push

    git push origin master
Ofir Lana
  • 383
  • 5
  • 13