aphexlog
aphexlog

Reputation: 1775

Gerrit: after add/commit to local git repo, I receive: [remote rejected] (no changes made) when trying to push to remote

The following is the output when trying to push to remote git repo:

Counting objects: 28, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (28/28), 3.28 KiB | 1.64 MiB/s, done.
Total 28 (delta 22), reused 0 (delta 0)
remote: Resolving deltas: 100% (22/22)
remote: Processing changes: refs: 1, done
remote: (W) No changes between prior commit 4075c99 and new commit bbb6b31
To http://172.16.0.5:8080/chef-repo
 ! [remote rejected] HEAD -> refs/for/chef-feature-1.0 (no changes made)
error: failed to push some refs to 'http://172.16.0.5:8080/chef-repo'

Note: before hand, I had amended my last commit

I see the changes are acknowledged when a commit so I do not understand why I cannot push them.

git diff 4075c99 bbb6b31 displays no output put I have been commiting things all day and the last push on gerrit was on the 20th (locally it was like 30 min ago).

here is my current git log output:

commit 8e3b769cf035a304d4b5bd796fd13737efaba01a (HEAD -> chef-feature-1.0)
Author: Aaron West <[email protected]>
Date:   Fri Dec 22 09:51:06 2017 -0600

    finalized oid1

    Change-Id: I1b2449a74a86aa5f02a75f5c768203a24860dfe1

commit 12b082629bfd14e63a7dca8a5c43f41db23ca64b
Author: Aaron West <[email protected]>
Date:   Fri Dec 22 09:49:01 2017 -0600

    cleaned up the oid.erb

    Change-Id: I0b906bbcb4b7b25bac41524b96d5133965ea93ea

Upvotes: 3

Views: 726

Answers (1)

mkasberg
mkasberg

Reputation: 17332

Gerrit is rejecting your push because 4075c99 and bbb6b31 are identical commits with different hashes.

The most common way that this happens is when you amend a commit (creating a new commit hash), but don't actually change anything:

$ git push origin HEAD:refs/for/master
$ git commit --amend
... don't make any changes ...
$ git push origin HEAD:refs/for/master

However, that's not the only way it can happen. There are other scenarios that will produce a similar error even though your most recent commit actually contains valid changes. For example, if you're two commits ahead (two unmerged Gerrit change sets), and you make changes to the most recent commit, but accidentally change the previous hash somehow (often with cherry-picking over an amended commit or with rebase -i):

... two commits ahead of Gerrit ...
$ git checkout HEAD~1
$ git commit --amend
... don't make any changes ...
$ git cherry-pick master
... make some valid changes that you want to push ...
$ git commit --amend
$ git push origin HEAD:refs/for/master
REMOTE REJECTED!

This is likely the case for you (and it may be deeper than 2 commits) because neither of the 2 most recent commits in your log have the hash that Gerrit is complaining about.

Regardless of how you arrived at this situation, the solution should be the same: Get Gerrit's version (exact hash match) of the commit it's complaining about and cherry-pick your work on top of it. With your example, the prior commit is 4075c99:

$ git checkout 4075c99
$ git cherry-pick <changes you want>
$ git push origin HEAD:refs/for/master

Upvotes: 2

Related Questions