Whenever I use hg amend or other commands that change history (for example hg rebase -s ... -d ...), certain commands, including hg push start to fail with abort: unknown revision error:
$ hg push -B my-branch
pushing to git+ssh://[email protected]:...
searching for changes
abort: unknown revision 'xxxxx'!
When using
hg amendor other history-altering commands in Mercurial (Hg), especially when working with the HgGit extension to interact with Git repositories, you might encounterabort: unknown revision 'xxxxx'!errors: often, this is because these operations rewrite history, which can confuse the mapping between Mercurial changesets and Git commits.To avoid this issue, follow these steps when you need to amend a commit or rebase:
use
hg commit --amendcarefully: Make sure you only amend commits that have not been pushed to a Git repository. Amending already pushed commits can create discrepancies between your local repository and the remote Git repository.Push changes immediately after amending: If you are amending a commit that is part of a series of commits not yet pushed to the remote Git repository, push your changes immediately after amending to minimize discrepancies.
Recreate the mapping: If you have already encountered the
unknown revisionerror, you may need to recreate the mapping between your Mercurial repository and the Git repository. That can involve pulling from the Git repository again, or usinghg stripto remove the problematic commits locally and then re-applying your changes.If you are aware of the implications and are certain that no other users will be affected (for example, in a personal project), you could use
hg push --forceto override the remote repository. Be very cautious with this approach, as it can lead to lost work for others.You can also test schacon/hg-git/issues/298