1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/bin/bash
target=""
source=""
PARAMS=""
while (( "$#" )); do
case "$1" in
-t|--merge-into)
target=$2
shift 2
;;
-f|--merge-from)
source=$2
shift 2
;;
--) # end argument parsing
shift
break
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAM="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
if [[ -z "${source// }" ]]; then
echo "Source branch is empty" >&2
exit 1
fi
if [[ -z "${target// }" ]]; then
echo "Target branch is empty" >&2
exit 1
fi
echo "merging ${source} into ${target} using branchTEMP"
# in case branchA is not our current branch
git checkout $target
# make merge commit but without conflicts!!
# the contents of 'ours' will be discarded later
git merge -s ours $source
# make temporary branch to merged commit
git branch branchTEMP
# get contents of working tree and index to the one of branchB
git reset --hard $source
# reset to our merged commit but
# keep contents of working tree and index
git reset --soft branchTEMP
# change the contents of the merged commit
# with the contents of branchB
git commit --amend
# get rid off our temporary branch
git branch -D branchTEMP
# verify that the merge commit contains only contents of branchB
git diff HEAD ${source}
|