Missing dependency in Gerrit
Asked Answered
B

3

3

I had four changes in Gerrit, each depending on previous one (except first, of course). I've abandoned second and third and reviewed first and fourth. Since first wasn't depending on anything, Gerrit managed to auto-merge it. Now, the fourth (depending on abandoned third) is a real problem.

Gerrit states Submitted, Merge Pending with:

Change could not be merged because of a missing dependency.
The following changes must also be submitted:

and giving me change-Id of both abandoned changes. How can I get rid of this chaos?

From what I've already learnt by googling and SO-ing (especially this and this one -- doesn't help much), the entire problem arose, because I haven't been using branches, only working directly on master.

Fine, I'll promise to be better next time, but how to fix current problem? I've tried to apply many solutions, found in the Internet or here, on SO, but none of them helps. Each git pull and git push claims, that both my local and remote are up-to-date, but I see no way to get rid of dependent change.

Baber answered 10/12, 2013 at 14:22 Comment(3)
you mean git push HEAD:refs/for/master gives you up-to-date?Highchair
I was also facing same problem , the workaround i am using is 1. clean your local repo 2. pull "Submitted, Merge Pending" commit and push it directly to remote "git push origin HEAD:refs/heads/<branch name>.Fp
Also check : #8737826Fp
S
6

You need to remove the two unwanted commits corresponding to the abandoned changes from the ancestry of commit 4, i.e. the desired state is for git log to only list commits 4 and 1. When that's done, pushing a new patch set should remove the stated dependency. Getting rid of commits 2 and 3 can be done in many ways, including

  • doing an interactive rebase (git rebase -i HEAD~4 and deleting the lines for the two commits you don't want), or
  • starting a new branch based on the tip of the upstream branch and cherry-picking commit 4.
Seay answered 10/12, 2013 at 15:13 Comment(1)
Thanks, doing an interactive rebase did the job perfectly and right after push Gerrit managed to auto-merge "previously unmergable" change.Baber
C
1

Ok, here is my revised answer

Starting point is where you have your 4 commits in a row:

#git log --graph --decorate --oneline
* 448fd95 (HEAD, master) Change 4
* 3950f5f Change 3
* 8753adf Change 2
* cdcfe20 Change 1

Next, create a temp branch from the head

#git branch temp
#git log --graph --decorate --onelin
* 448fd95 (HEAD, temp, master) Change 4
* 3950f5f Change 3
* 8753adf Change 2
* cdcfe20 Change 1

Now you need to reset your master to get rid of the unwanted history:

#git reset --hard cdcfe20
HEAD is now at cdcfe20 Change 1
#git log --graph --decorate --oneline
* cdcfe20 (HEAD, master) Change 1

Cherry pick your change 4 into the master

#git cherry-pick 448fd95
[master 19c5ba1] Change 4
 1 file changed, 1 insertion(+), 1 deletion(-)
#git log --graph --decorate --oneline
* 19c5ba1 (HEAD, master) Change 4
* cdcfe20 Change 1

Now you can push the last change to gerrit and your dependencies are fixed

Crusado answered 11/12, 2013 at 0:48 Comment(2)
You don't want to merge from commit 4. That'll just bring in the full history of commit 4 with the unwanted commits, plus you now have a merge commit that you don't really want. But branching from commit 1 (or any newer commit from the destination branch) and cherry-picking commit 4 is fine.Debut
@Crusado Thanks for your support (+1), however I picked Magnus' answer with interactive rebase as it was easier (less steps) and worked fine for me.Baber
C
1

I used the answer from Magnus and did the interactive rebase and removed my previous commit but still had some merge conflicts. Then I manually updated the files to resolve the conflicts.

Finally added the modified files, then ran "git rebase --continue" to resolve the issue.

Conscience answered 16/4, 2017 at 20:0 Comment(1)
@Pierre.Vriens. .Yes.. I know. I wanted to thank him. but could not add the comments that's why.Conscience

© 2022 - 2024 — McMap. All rights reserved.