首页 > 解决方案 > 过滤特定作者的差异

问题描述

我想在 2 个分支之间区分一个文件,并仅对来自特定作者的差异应用补丁(类似于 git blame diff?)。我需要对许多文件执行此操作。

基本上,在 IntelliJ 上,当我尝试在其合并工具窗口中解决冲突时,我可以选择annotate显示每一行的作者,为此我可以手动应用来自另一个分支的作者的非冲突和冲突更改. 我想以编程方式执行此操作。

我试图通过以下方式获得特定作者的提交:

git log branch1..branch2 --author '\(author1\|author2)' --reverse --pretty=%H $file

接着

git cherry-pick -n --strategy=recursive -n $commit -X theirs

但是-X theirs,如果发生冲突,只会从另一个分支中选择提交。我也打算从其他分支中挑选不冲突的差异,但仅限于特定作者。

我如何实现这一目标?

我正在使用此脚本为目录中的所有文件运行它:

for file in ./directory/*; do
    fileNameWithExtension="${file##*/}"
    fileNameWithoutExtension="${fileNameWithExtension%.*}"
    git log branch1..branch2 --author '\(author1\|author2\)' --reverse --pretty=%H $file |
    while read commit; do
        git stash
        git cherry-pick -n --strategy=recursive -n $commit -X theirs
        git reset .
        git add $file
        git commit -m "Random commit to commit the changes: new updates for $fileNameWithExtension" || exit
    done
done

标签: gitjgit

解决方案


推荐阅读