git-bash脚本以自动保留合并冲突

时间:2018-10-19 18:25:48

标签: bash git versioning merge-conflict-resolution git-merge-conflict

由于每个版本上都会更新一个版本控制文件,因此我的团队通常会遇到合并冲突。该文件是version.txt。

这是到目前为止我要去的地方。我只希望它通过接受当前分支版本或传入分支来解决version.txt冲突。当我使用以下脚本时,我的PR表示为空,我认为这意味着它已使用我们的策略丢弃了所有本地更改。

我希望脚本保留所有本地更改-除了引起冲突的更改之外,解决冲突并推送到当前功能分支。我该怎么做?

#!/bin/bash

set -e

FEATURE_BRANCH=$1
DESTINATION_BRANCH=$2
read -p "Would you like to accept incoming or outgoing changes? {in/out}" OP

if [ $OP = "in" ]; then
  MERGE_STRATEGY="Xtheirs"
else
  MERGE_STRATEGY="Xours"
fi
echo "Pulling current branch"
git pull
echo "Checking out current branch"
git checkout $FEATURE_BRANCH
echo "Pulling destination branch"
git pull origin $DESTINATION_BRANCH -${MERGE_STRATEGY} <<-EOF
  :wq #this part is necessary because vim text editor is automatically opened to display a merge message.
EOF
echo "Conflict resolved, pushing back to feature branch"
git push origin $FEATURE_BRANCH
echo "PR ready for merge"

0 个答案:

没有答案