Skip to content

Instantly share code, notes, and snippets.

@zjr
Last active April 10, 2019 15:51
Show Gist options
  • Save zjr/c1bbccc09ddea2f478ba4bd8b882ed18 to your computer and use it in GitHub Desktop.
Save zjr/c1bbccc09ddea2f478ba4bd8b882ed18 to your computer and use it in GitHub Desktop.
Shell script to automatically path moved files.
#!/usr/bin/env bash
set -e
# Establish the base comparison revision, update your branch for comparing to HEAD.
branch=chartreux
base=$(git merge-base head ${branch})
# Conflicts listed line by line in format of `<old path> <new path>`, careful to note the space between.
conflicts="oldFilePath1.js newFilePath1.js
oldFilePath2.js newFilePath2.js"
while read -r line; do
files=(${line})
old=${files[0]}
new=${files[1]}
git diff ${base}..${branch} ${old} > patch_file
patch -p1 ${new} patch_file
done <<< "$conflicts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment