So, here is my solution:
git rebase <branch> \
-ix "git rev-parse --short HEAD > tmp && \
echo 'from: $<branch_shortid>' > tmp && \
git commit --amend -F tmp"
Make sure that branch_shortid
is correct and was generated on the branch you wish to rebase content from.
Disclaimer: I am not sure if this will work in all cases, esspecially if you have some strange or complicated referencing systems going on. I ran this on a very simple git repo generated by:
$ git init
$ echo "a" > a.txt && git add . && git commit -m "first commit"
$ git checkout -b "feature1"
$ echo "b" > b.txt && git add . && git commit -m "second commit"
$ echo "c" > c.txt && git add . && git commit -m "third commit"
$ feature1id=$(git rev-parse --short HEAD)
$ git checkout master
$ git rebase feature1 \
-ix "git rev-parse --short HEAD > tmp && \
echo 'from: $feature1_id' > tmp && \
git commit --amend -F tmp"
Here is corresponding output:

Discussion:
As pointed out earlier, I think that you using git reflog
is a better solution for investigating from which commit on which branch was merged onto the desired one.
The point of rebasing is to apply commits onto the top of another branch, as if that were commit structure in the first place:
Rebasing produces a linear history.
git rebase master -x
work?