首页 > 解决方案 > 在 `git rebase` 期间自动化 `--ours` 和 `--theirs`

问题描述

我有一个 500 次提交的长变基,我必须为每个提交指定相同的文件来支持github checkout --ours file.py--theirs;有没有办法通过告诉Git Bash将此首选项应用于所有进一步的冲突来自动执行此操作?

标签: gitgithubgit-bash

解决方案


如果这是一个轻率的过程,那么请随意编写脚本……例如:

git rebase blahblahblah
if [ $? -ne 0 ]; then
    # rebase stopped for whatever reason
    while true; do
        git checkout --ours blahblah
        # more commands to specify what should be attempted with each file
        git add . # add all files.... perhaps something a little mlre specific would help
        # let's try again
        GIT_EDITOR=/bin/true git rebase --continue
        if [ $? -eq 0 ]; then
            break # we are done
        fi
    done
fi

推荐阅读