Skip to content

Instantly share code, notes, and snippets.

@marcobazzani
Last active April 10, 2020 22:45
Show Gist options
  • Save marcobazzani/306e3589f918575d20d821522a6fef77 to your computer and use it in GitHub Desktop.
Save marcobazzani/306e3589f918575d20d821522a6fef77 to your computer and use it in GitHub Desktop.
### put the 3 files anywhere in and run as /path/to/files/merge BRANCH
#!/bin/sh
#findup
pwd="`pwd`"
start="$pwd"
while [ ! "$pwd" -ef .. ]; do
[ -e "$1" ] && echo -n "$pwd" && exit
cd .. || exit 1
pwd="`pwd`"
done
exit 1
#!/bin/sh
#merge
cd `findup .git`
PATH=$PATH:$( dirname "${BASH_SOURCE[0]}" )
HEAD=`git rev-parse --abbrev-ref HEAD`
echo "* merge=newest" > .gitattributes
sed -ie '/merge "newest"/,+2d' .git/config
echo "[merge \"newest\"]" >> .git/config
echo -e "\tname = Merge by newest commit" >> .git/config
echo -e "\tdriver = git-merge-newest %O %A %B %L %P $HEAD $1" >> .git/config
git merge $1
sed -ie '/merge "newest"/,+2d' .git/config
rm .gitattributes
cd -
#!/bin/sh
#git-merge-newest
if git merge-file -p -q "$2" "$1" "$3" > /dev/null;
then git merge-file "$2" "$1" "$3";
else
MINE=$(git log --format="%ct" --no-merges "$6" -1 $5);
THEIRS=$(git log --format="%ct" --no-merges "$7" -1 $5);
if [ $MINE -gt $THEIRS ]; then
git merge-file -q --ours "$2" "$1" "$3" >/dev/null
else
git merge-file -q --theirs "$2" "$1" "$3">/dev/null
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment