4

I have two commits. Commit B depends on commit A. Commit A was abandoned. Now I am getting error for merging B. It says submitted, merge pending due to dependency of B on A.

I have googled around but cant find an exact answer. I need step by step solution as I am a novice in git and am finding hard to understand how to resolve this.

This is what happened.

  1. git commit in local for A.

  2. git push for A in remote.

  3. A got abandoned, but my local git has commit A.

  4. git commit in local for B in same branch (Makes B dependent on A).

  5. git push B in remote in same branch.

  6. Now B is not merging since A is abandoned.

I need to merge B and I want dependency on A removed. Hope its clear now!

Here is Server error:

Change 1184 - Submitted, Merge Pending

In comments:

Gerrit Code Review

Change could not be merged because of a missing dependency. The following changes must also be submitted: (commit-id, which was abandoned)

Will rebase work? If so, how to do it?

VinayChoudhary99
  • 846
  • 3
  • 13
  • 26
  • Your question is rather unclear. What is the exact comand you were running? What is the output? What are you trying to achieve? I don't think this can be answered with the information given. – Sven Marnach Aug 11 '15 at 17:22
  • So by "B is not merging", you mean the server rejects the commit because it's not a direct descendent of the current head on the server? – Sven Marnach Aug 11 '15 at 17:31
  • could you post the error message? – mbenegas Aug 11 '15 at 17:34
  • @SvenMarnach No Both commits are pushed on server. But A is abandoned, hence not merged and B is not merging because it depends on A. – VinayChoudhary99 Aug 11 '15 at 17:42
  • I'm not familiar with Gerrit, and I have no idea what has been going on there. If you push a branch to the git server, all commits reachable by a head commit will be automatically included, so I'm not sure how it is even possible to end up in this situation. My guess is that you will have to call `git fetch` to get the current version of your branch on the server, rebase or cherry-pick your commit B on top of the remote head and then push again. Since I don't really know what's going on, this is more of an educated guess than an answer. – Sven Marnach Aug 11 '15 at 17:47

2 Answers2

11

There are several ways to fix your problem. Pick whichever you feel most comfortable with.

Here is one:

  1. git checkout yourbranch (make sure you are on the right branch)
  2. git reset --hard A^ (reset everything to the commit before A)
  3. git cherry-pick B (where B is the hash of the commit you want to keep)
  4. git log (confirm that it is what you wanted)
  5. git push --force (may need to specify other options depending on how you usually push)

Here is another, result is equivalent:

  1. git checkout yourbranch (make sure you are on the right branch)
  2. git rebase --onto A^ A (rebase everything after A on top of the commit before A, effectively removing A)
  3. git log (confirm that it is what you wanted)
  4. git push --force (may need to specify other options depending on how you usually push)

Here is a third, result still equivalent:

  1. git checkout yourbranch (make sure you are on the right branch)
  2. git rebase --interactive A^ (will open up your editor)
  3. Delete the line showing commit A, save and close
  4. git log (confirm that it is what you wanted)
  5. git push --force (may need to specify other options depending on how you usually push)
jsageryd
  • 4,234
  • 21
  • 34
  • 1
    Yes, if your history is `X <- A <- B`, then `git rebase --onto X B~1` is synonymous to `git rebase --onto A^ A` (second solution suggested above), because `X` is the commit before `A` (`A^` means `A`'s first parent) and `A` is the commit before `B` (`B~1` is equivalent to `B^`, `B`'s first parent). Nice that it worked out for you. – jsageryd Aug 17 '15 at 00:44
1

Here is an issue like yours.

If committ B has a dependency on A, then B cannot be merged until A is merged. Since you have abandoned A, Gerrit will not automatically merge B.

What you will need to do is modify B (perhaps using git rebase) so that it no longer depends on A, and resubmit the change to Gerrit.

how do I rebase / merge it?

git-review -d 1184 
git rebase origin/master
git status
<edit "both modified" files in status report>
git add <files>
git rebase --continue
git review

Find more useful information here about this kind of issue.

Community
  • 1
  • 1
Moises Gonzaga
  • 151
  • 1
  • 17