git diff commit_A commit_B
shows me all the differences between A
and B
Within the range of commits A..B
there are commits --author=me
and --author=someone else
Is there a way to get the git diff
for my cumulative changes between A
and B
, excluding changes by others?
I imagine one potential solution would be to parse git log --author=me
and "sum" together the diffs for each commit. Another potential idea could be to take the git blame
at point B
and filter by lines that were changed between A
and B
.
Context:
Suppose I am working on a large feature over the course of some long period of time. During this work, I make many commits of subfeatures. In order to keep up to date with the latest codebase, git pull
creates merge commits with other contributors' contributions. I want to be able to see the cumulative changes I have made so far without seeing everyone else's changes. Assume there are no merge conflicts (we touch different areas of code, but potentially in the same file.
Is there a way to get the git diff for my cumulative changes between A and B, excluding changes by others?
Not directly, no.
I imagine one potential solution would be to parse git log --author=me and "sum" together the diffs for each commit.
The same idea, but I think easier to achieve (although I'd expect frequent problems with patches not applying properly): make a temporary branch starting from commit A
, cherry-pick every commit you want to keep (yours or theirs) while ignoring the ones you want to skip, then diff the final result against the original. Once satisfied with the diff, discard the temporary branch. Hence:
git checkout -b temp A
for commit in $(git rev-list A..B); do
if want_commit $commit; then git cherry-pick $commit; fi
done
git diff A
git checkout realbranch; git branch -D temp
(There's no need to name the temporary branch: a detached HEAD will serve as the temporary branch. The above is mainly for illustration.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With