git diff commit_A commit_B
向我展示了 A
之间的所有差异和 B
在提交范围内 A..B
有提交 --author=me
和 --author=someone else
有没有办法得到git diff
对于我的 A
之间的累积变化和 B
, 不包括其他人的更改?
我想一个潜在的解决方案是解析 git log --author=me
并将每次提交的差异“相加”。另一个潜在的想法可能是采用 git blame
在点 B
并按 A
之间更改的行过滤和 B
.
上下文:
假设我在很长一段时间内致力于一项大型功能。在这项工作中,我提交了许多子功能。为了与最新的代码库保持同步,git pull
与其他贡献者的贡献创建 merge 提交。我希望能够看到我到目前为止所做的累积更改,而无需看到其他人的更改。假设没有 merge 冲突(我们触及代码的不同区域,但可能在同一个文件中。
最佳答案
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.
相同的想法,但我认为更容易实现(尽管我预计补丁不会正确应用会经常出现问题):从提交 A
开始创建一个临时分支,cherry-pick 每个提交你想保留(你的或他们的)而忽略你想跳过的那些,然后将最终结果与原始结果进行比较。一旦对差异感到满意,就丢弃临时分支。因此:
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
(不需要命名临时分支:一个detached HEAD作为临时分支,以上主要是为了说明。)
关于git diff 只有我的改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32765647/