Search code examples
gitgerrit

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.


Solution

  • 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.