Marian Harbach | ebeb154 | 2019-12-13 10:42:46 +0100 | [diff] [blame] | 1 | :linkattrs: |
Sven Selberg | 183b4fa | 2016-04-08 13:58:38 +0200 | [diff] [blame] | 2 | = same Change-Id in multiple changes |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 3 | |
| 4 | With this error message Gerrit rejects to push a commit if it |
David Pursehouse | 2c6f638 | 2014-09-04 13:06:19 +0900 | [diff] [blame] | 5 | contains the same Change-Id as a predecessor commit. |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 6 | |
| 7 | The reason for rejecting such a commit is that it would introduce, for |
| 8 | the corresponding change in Gerrit, a dependency upon itself. Gerrit |
| 9 | prevents such dependencies between patch sets within the same change |
| 10 | to keep the review process simple. Otherwise reviewers would not only |
| 11 | have to review the latest patch set but also all the patch sets the |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 12 | latest one depends on. |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 13 | |
| 14 | This error is quite common, it appears when a user tries to address |
| 15 | review comments and creates a new commit instead of amending the |
| 16 | existing commit. Another possibility for this error, although less |
| 17 | likely, is that the user tried to create a patch series with multiple |
David Pursehouse | 2c6f638 | 2014-09-04 13:06:19 +0900 | [diff] [blame] | 18 | changes to be reviewed and accidentally included the same Change-Id |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 19 | into the different commit messages. |
| 20 | |
| 21 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 22 | == Example |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 23 | |
| 24 | Here an example about how the push is failing. Please note that the |
| 25 | two commits 'one commit' and 'another commit' both have the same |
David Pursehouse | 2c6f638 | 2014-09-04 13:06:19 +0900 | [diff] [blame] | 26 | Change-Id (of course in real life it can happen that there are more |
| 27 | than two commits that have the same Change-Id). |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 28 | |
| 29 | ---- |
| 30 | $ git log |
| 31 | commit 13d381265ffff88088e1af88d0e2c2c1143743cd |
| 32 | Author: John Doe <john.doe@example.com> |
| 33 | Date: Thu Dec 16 10:15:48 2010 +0100 |
| 34 | |
| 35 | another commit |
| 36 | |
| 37 | Change-Id: I93478acac09965af91f03c82e55346214811ac79 |
| 38 | |
| 39 | commit ca45e125145b12fe9681864b123bc9daea501bf7 |
| 40 | Author: John Doe <john.doe@example.com> |
| 41 | Date: Thu Dec 16 10:12:54 2010 +0100 |
| 42 | |
| 43 | one commit |
| 44 | |
| 45 | Change-Id: I93478acac09965af91f03c82e55346214811ac79 |
| 46 | |
| 47 | $ git push ssh://JohnDoe@host:29418/myProject HEAD:refs/for/master |
| 48 | Counting objects: 8, done. |
| 49 | Delta compression using up to 2 threads. |
| 50 | Compressing objects: 100% (2/2), done. |
| 51 | Writing objects: 100% (6/6), 558 bytes, done. |
| 52 | Total 6 (delta 0), reused 0 (delta 0) |
| 53 | To ssh://JohnDoe@host:29418/myProject |
Sven Selberg | 183b4fa | 2016-04-08 13:58:38 +0200 | [diff] [blame] | 54 | ! [remote rejected] HEAD -> refs/for/master (same Change-Id in multiple changes. |
| 55 | Squash the commits with the same Change-Id or ensure Change-Ids are unique for each commit) |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 56 | error: failed to push some refs to 'ssh://JohnDoe@host:29418/myProject' |
Sven Selberg | 183b4fa | 2016-04-08 13:58:38 +0200 | [diff] [blame] | 57 | |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 58 | ---- |
| 59 | |
David Pursehouse | a43ad9c | 2014-09-04 13:15:15 +0900 | [diff] [blame] | 60 | If it was the intention to rework a change and push a new patch |
| 61 | set, the problem can be fixed by squashing the commits that contain the |
David Pursehouse | 2c6f638 | 2014-09-04 13:06:19 +0900 | [diff] [blame] | 62 | same Change-Id. The squashed commit can then be pushed to Gerrit. |
David Pursehouse | a43ad9c | 2014-09-04 13:15:15 +0900 | [diff] [blame] | 63 | |
| 64 | To squash the commits, use `git rebase -i` to do an interactive rebase. For |
| 65 | the example above where the last two commits have the same Change-Id, |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 66 | this means an interactive rebase for the last two commits should be |
| 67 | done. For further details about the git rebase command please check |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 68 | the link:http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html[Git documentation for rebase,role=external,window=_blank]. |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 69 | |
| 70 | ---- |
| 71 | $ git rebase -i HEAD~2 |
| 72 | |
| 73 | pick ca45e12 one commit |
| 74 | squash 13d3812 another commit |
| 75 | |
| 76 | [detached HEAD ab37207] squashed commit |
| 77 | 1 files changed, 3 insertions(+), 0 deletions(-) |
| 78 | Successfully rebased and updated refs/heads/master. |
| 79 | |
| 80 | $ git log |
| 81 | commit ab37207d33647685801dba36cb4fd51f3eb73507 |
| 82 | Author: John Doe <john.doe@example.com> |
| 83 | Date: Thu Dec 16 10:12:54 2010 +0100 |
| 84 | |
| 85 | squashed commit |
| 86 | |
| 87 | Change-Id: I93478acac09965af91f03c82e55346214811ac79 |
| 88 | |
| 89 | $ git push ssh://JohnDoe@host:29418/myProject HEAD:refs/for/master |
| 90 | Counting objects: 5, done. |
| 91 | Writing objects: 100% (3/3), 307 bytes, done. |
| 92 | Total 3 (delta 0), reused 0 (delta 0) |
| 93 | To ssh://JohnDoe@host:29418/myProject |
| 94 | * [new branch] HEAD -> refs/for/master |
| 95 | ---- |
| 96 | |
| 97 | If it was the intention to create a patch series with multiple |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 98 | changes to be reviewed, each commit message should contain the |
David Pursehouse | 2c6f638 | 2014-09-04 13:06:19 +0900 | [diff] [blame] | 99 | Change-Id of the corresponding change in Gerrit. If a change in |
| 100 | Gerrit does not exist yet, the Change-Id should be generated (either |
| 101 | by using a link:cmd-hook-commit-msg.html[commit hook] or by using EGit) or the Change-Id could be |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 102 | removed (not recommended since then amending this commit to create |
David Pursehouse | 2c6f638 | 2014-09-04 13:06:19 +0900 | [diff] [blame] | 103 | subsequent patch sets is more error prone). To change the Change-Id |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 104 | of an existing commit do an interactive link:http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html[git rebase,role=external,window=_blank] and fix the |
Edwin Kempin | efb5f9a | 2010-12-16 11:02:00 +0100 | [diff] [blame] | 105 | affected commit messages. |
| 106 | |
| 107 | |
| 108 | GERRIT |
| 109 | ------ |
| 110 | Part of link:error-messages.html[Gerrit Error Messages] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 111 | |
| 112 | SEARCHBOX |
| 113 | --------- |