The B-52s Bassist
The B-52s Bassist

Reputation: 55

How to resolve "ANCESTOR OUTDATED" issue on Gerrit?

My patch on Gerrit needs to be merged, but there is an error of "ANCESTOR OUTDATED". This is because the commit that my patch depends on has been outdated/abandoned, and replaced with a new merged commit.

I thought that I could simply do git rebase -i HEAD~2 and edit the dependency. By editing the dependency, I mean that once I rebased onto the dependency commit (1 commit behind HEAD), I could cherrypick the new changes there.

However, I get a long error message:

interactive rebase in progress; onto SHA#
Last command done (1 command done):
   edit *** DEPENDENCY
Next command to do (1 remaining command):
   pick *** MY PATCH
You are currently rebasing branch 'temp' on 'SHA#'.

nothing to commit, working directory clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

Otherwise, please use 'git reset'

How can I simply update the commit that is right behind my HEAD and then solve this ANCESTOR OUTDATED issue on Gerrit?

Edit: The reason why I can't do this rebasing quickly with Gerrit's "Rebase Change" button is because it says that there are merge conflicts and it cannot due it automatically.

Upvotes: 0

Views: 994

Answers (2)

The B-52s Bassist
The B-52s Bassist

Reputation: 55

My solution (must be done in the working directory of your project):

  1. git fetch ssh://repo_of_project official_branch
  2. git checkout -b my_branch FETCH_HEAD
  3. cherry-pick your latest patch from Gerrit: git fetch ssh://repo_of_project refs/changes/xx/SHA_ID/xx && git cherry-pick FETCH_HEAD
  4. Resolve any merge conflicts
  5. git add
  6. git commit --amend
  7. git push ...

--> This pretty much fixes your branches outdated commit history and puts your patch correctly at the tip.

Upvotes: 0

Enrique S. Filiage
Enrique S. Filiage

Reputation: 810

I would recommend you:

  • checkout to you desired ancestral,
  • cherry-pick your change,
  • test you change/solve any merge conflict (if any)
  • commit-ammend*
  • finally, push

*I'm considering you commit has a gerrit's Change-Id; if doesn't, you should do a regular commit to create it (the commit-msg hook is responsible by that).

Also, when I say push, I'm referring to gerrit's approach (which is a git push origin HEAD:refs/for/master not simply git push).

Upvotes: 1

Related Questions