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