git diff 只有我的改变

标签 git git-diff

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/

相关文章:

git - 从 Git 中的多个提交中导出修改后的文件

python - edX 供应问题 : get stuck at, 任务:[edxapp |将 edx-platform repo check out 到 {{edxapp_code_dir}}]

git - 用于使用 Homebrew 软件升级到不易受攻击的 git 版本 (CVE-2014-9390)

git - 使用 BeyondCompare 查看 GIT 中文件之间的差异

git - 如何将整个 git repo 输出到单个文件?

linux - 如何使 diffstat 计数已删除和新添加的文件到 LOC 计数?

git - 如何获取自创建分支以来已更改文件的当前文件路径列表

windows - msysgit 'submodule update' 在 Windows 7 中速度过慢

git - 如何恢复 `magit` 中旧提交的更改?

git - 显示 Git 索引中和工作副本中更改的文件