mirror of
https://github.com/iwata/git-now.git
synced 2026-09-16 02:16:25 -04:00
rebase option move to rebase command
This commit is contained in:
parent
adc453f9a8
commit
0d67f9eb92
34
git-now
34
git-now
|
|
@ -7,7 +7,7 @@ if [ $# -eq 0 ]
|
|||
then
|
||||
git add -u
|
||||
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
|
||||
elif [ $1 != "--rebase" ]
|
||||
else
|
||||
then
|
||||
if [ $1 != "--all" ]
|
||||
then
|
||||
|
|
@ -17,36 +17,4 @@ then
|
|||
git add .
|
||||
fi
|
||||
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
|
||||
else
|
||||
if [ $# -eq 1 ]
|
||||
then
|
||||
FIRST_NOW_COMMIT=`git log --pretty=oneline --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1`
|
||||
INITIAL_COMMIT=`git log --pretty=oneline | tail -n 1 | cut -d " " -f 1`
|
||||
|
||||
if [ ${FIRST_NOW_COMMIT} != ${INITIAL_COMMIT} ]
|
||||
then
|
||||
git rebase -i ${FIRST_NOW_COMMIT}^
|
||||
else
|
||||
WORKING_BRANCH=`git branch -l | grep "*" | cut -d " " -f 2`
|
||||
|
||||
git checkout ${FIRST_NOW_COMMIT}
|
||||
git commit --amend
|
||||
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
|
||||
fi
|
||||
else
|
||||
BASE_BRANCH=$2
|
||||
WORKING_BRANCH=`git branch -l | grep "*" | cut -d " " -f 2`
|
||||
COMMON_ANCESTOR_COMMIT=`git merge-base ${BASE_BRANCH} ${WORKING_BRANCH}`
|
||||
FIRST_NOW_COMMIT=`git log ${COMMON_ANCESTOR_COMMIT}.. --pretty=oneline --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1`
|
||||
INITIAL_COMMIT=`git log --pretty=oneline | tail -n 1 | cut -d " " -f 1`
|
||||
|
||||
if [ ${FIRST_NOW_COMMIT} != ${INITIAL_COMMIT} ]
|
||||
then
|
||||
git rebase -i ${FIRST_NOW_COMMIT}^
|
||||
else
|
||||
git checkout ${FIRST_NOW_COMMIT}
|
||||
git commit --amend
|
||||
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
66
git-now-rebase
Executable file
66
git-now-rebase
Executable file
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/sh
|
||||
|
||||
usage_exit() {
|
||||
echo "Usage: git now rebase [-h] [-p] [-r remote] [base_branch] " 1>&2
|
||||
exit 1
|
||||
}
|
||||
#
|
||||
# Options
|
||||
#
|
||||
while getopts "pr:h" GETOPTS
|
||||
do
|
||||
case $GETOPTS in
|
||||
p) PUSH_FLAG=yes
|
||||
;;
|
||||
r) REMOTE_NAME=$OPTARG
|
||||
;;
|
||||
h) usage_exit
|
||||
;;
|
||||
*) usage_exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
PREFIX="from now"
|
||||
WORKING_BRANCH=`git branch -l | grep "*" | cut -d " " -f 2`
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
FIRST_NOW_COMMIT=`git log --pretty=oneline --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1`
|
||||
INITIAL_COMMIT=`git log --pretty=oneline | tail -n 1 | cut -d " " -f 1`
|
||||
|
||||
if [ ${FIRST_NOW_COMMIT} != ${INITIAL_COMMIT} ]
|
||||
then
|
||||
echo "git rebase -i ${FIRST_NOW_COMMIT}^"
|
||||
else
|
||||
echo "git checkout ${FIRST_NOW_COMMIT}"
|
||||
echo "git commit --amend"
|
||||
echo "git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}"
|
||||
fi
|
||||
else
|
||||
BASE_BRANCH=$1
|
||||
COMMON_ANCESTOR_COMMIT=`git merge-base ${BASE_BRANCH} ${WORKING_BRANCH}`
|
||||
FIRST_NOW_COMMIT=`git log ${COMMON_ANCESTOR_COMMIT}.. --pretty=oneline --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1`
|
||||
INITIAL_COMMIT=`git log --pretty=oneline | tail -n 1 | cut -d " " -f 1`
|
||||
|
||||
if [ ${FIRST_NOW_COMMIT} != ${INITIAL_COMMIT} ]
|
||||
then
|
||||
echo "git rebase -i ${FIRST_NOW_COMMIT}^"
|
||||
else
|
||||
echo "git checkout ${FIRST_NOW_COMMIT}"
|
||||
echo "git commit --amend"
|
||||
echo "git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $PUSH_FLAG ]
|
||||
then
|
||||
if [ $REMOTE_NAME ]
|
||||
then
|
||||
echo "git push --set-upstream ${WORKING_BRANCH} ${REMOTE_NAME}/${WORKING_BRANCH}"
|
||||
else
|
||||
echo "git push"
|
||||
fi
|
||||
fi
|
||||
Loading…
Reference in a new issue