Last active
June 21, 2018 01:33
-
-
Save mark-sch/1816d19b9ed5113bb9862da416b17418 to your computer and use it in GitHub Desktop.
Bash script to automate GIT upstream remote cherry picking - by maintaining a merge.history file of cherry pick ranges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "" | |
echo "///////////////////////////////////////////////////////////////////////" | |
echo "/ Display new upstream/master commits since last origin/master merge: /" | |
echo "/ /" | |
echo "/ Or start with further command line params /" | |
echo "/ \"step1\" = checkout new upmerge branch, merge and interactively add /" | |
echo "/ \"step2\" = commit new branch, merge with master and delete upmerge /" | |
echo "///////////////////////////////////////////////////////////////////////" | |
echo "" | |
git fetch upstream | |
git log $(tail -n 1 merge.history)..upstream/master --pretty=oneline | |
read -rsp $'\nPress d for diff display, or any other to continue...\n' -n 1 key | |
if [ "$key" == "d" ]; then | |
git log $(tail -n 1 merge.history)..upstream/master -p | |
read -rsp $'\nPress enter to continue...\n' | |
fi | |
if [ "$1" == "step1" ]; then | |
### checkout new branch upmerge and cherry pick from laste merge id to current upstream/master id | |
git pull origin master | |
git checkout -b upmerge | |
git cherry-pick --no-commit $(tail -n 1 merge.history)..upstream/master | |
### git merge --no-commit --no-ff upstream/master | |
git reset HEAD | |
git add --interactive | |
git status | |
fi | |
if [ "$1" == "step2" ]; then | |
### write last commit id from upstream/master to merge.history | |
echo "Update merge.history file..." | |
echo -n ".." >> merge.history | |
git log upstream/master -1 --pretty=format:"%h" >> merge.history | |
echo -n " // `date`" >> merge.history | |
### add new line | |
echo "" >> merge.history | |
### save starting point for next merge session | |
git log upstream/master -1 --pretty=format:"%h" >> merge.history | |
git add merge.history | |
git commit -m "Merged selected patches from upstream, `date`" | |
git checkout . | |
git checkout master | |
git merge upmerge | |
git branch -D upmerge | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment