diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
index 804abe8999f36760dff164aa3c72d87e2b60fd73_bWVyY3VyaWFsL2NtZHV0aWwucHk=..39163708825cd504f75e212c1d3f95698ded4c6f_bWVyY3VyaWFsL2NtZHV0aWwucHk= 100644
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2619,6 +2619,11 @@
                 message = old.description()
 
             pureextra = extra.copy()
+            if 'amend_source' in pureextra:
+                del pureextra['amend_source']
+            pureoldextra = old.extra()
+            if 'amend_source' in pureoldextra:
+                del pureoldextra['amend_source']
             extra['amend_source'] = old.hex()
 
             new = context.memctx(repo,
@@ -2636,7 +2641,7 @@
                 and newdesc == old.description()
                 and user == old.user()
                 and date == old.date()
-                and pureextra == old.extra()):
+                and pureextra == pureoldextra):
                 # nothing changed. continuing here would create a new node
                 # anyway because of the amend_source noise.
                 #
diff --git a/mercurial/commands.py b/mercurial/commands.py
index 804abe8999f36760dff164aa3c72d87e2b60fd73_bWVyY3VyaWFsL2NvbW1hbmRzLnB5..39163708825cd504f75e212c1d3f95698ded4c6f_bWVyY3VyaWFsL2NvbW1hbmRzLnB5 100644
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1617,6 +1617,9 @@
         if not allowunstable and old.children():
             raise error.Abort(_('cannot amend changeset with children'))
 
+        newextra = extra.copy()
+        newextra['branch'] = branch
+        extra = newextra
         # commitfunc is used only for temporary amend commit by cmdutil.amend
         def commitfunc(ui, repo, message, match, opts):
             return repo.commit(message,