How to get diff, including all file changes, for a list of commit ids?
I have a list of commits from 2 branches, I would like to find the diff and confirm if all the commits from branch 1 are already available in branch 2.
The list is around 100+ commits, and i would like to get a single diff file for it.
The most basic answer to your question would be to use
git patch-id. See the description from
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.
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
--right-only. Please see
git-log(1) — they are described very clearly there.
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.