Basic method
The most basic answer to your question would be to use git patch-id
. See the description from git-patch-id(1)
:
A "patch ID" is nothing but a SHA-1 of the diff associated with a patch, with whitespace and line numbers ignored. As such, it’s "reasonably stable", but at the same time also reasonably unique, i.e., two patches that have the same "patch ID" are almost guaranteed to be the same thing.
IOW, you can use this thing to look for likely duplicate commits.
However, git patch-id
has somewhat clunky interface — it demands a diff file on standard input. So in your case, for a commit with id COMMIT-ID
, you could use:
git diff COMMIT-ID~ COMMIT-ID | git patch
Be wary that output checksum of git patch
is different for some differences in input diff (for example, if you add the -U
option, checksum changes).
There is a better way!
It turns out that there is a tool which wraps git patch-id
. To get all commits from branch ONE
, diffs of which aren't available on branch TWO
just use git log
with some extra options:
git log --cherry-pick --right-only --oneline --no-abbrev-commit TWO...ONE
The "business" options are --cherry-pick
and --right-only
. Please see git-log(1)
— they are described very clearly there.
Getting diff?
As to getting a single diff from these commits, I'm afraid that's not possible if they won't happen to be consecutive. Remember that diffs are based on the previous state (commit) in the repository. Your best bet would be to cherry-pick the commits to a stable branch and brace yourself for some conflict resolving.