git - 过滤特定作者的差异
问题描述
我想在 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
解决方案
推荐阅读
- angular - 我可以将角度 pwa 用于角度 7 吗?
- sass - 如何在 Visual Studio 2019 for Mac 中编译 Sass?
- java - 之前发生的属性如何与可见性和顺序相关?
- oracle - 更好的开关盒解决方案
- flutter - 断言失败:在 Flutter 中使用 Navigator.popUntil() 时 !_debugLocked 不正确
- javascript - javascript 上的评论结构是什么?
- python - 获取缩短列表的numpy数组?
- c# - 在 HoloLens 上部署 Tensorflow 训练模型
- html - 如何让div背景滑入?
- visual-studio - VS 2019 更新后尝试构建 Xamarin.Android 时出错