Skip to content

Instantly share code, notes, and snippets.

@iwata
Forked from nobeans/.vimrc
Created August 24, 2011 01:05
Show Gist options
  • Save iwata/1167062 to your computer and use it in GitHub Desktop.
Save iwata/1167062 to your computer and use it in GitHub Desktop.
making convenient git commit
nnoremap <Space>gn :<C-u>w<CR>:Git now<CR>
nnoremap <Space>gN :<C-u>w<CR>:Git now --all<CR>
#!/bin/sh
PREFIX="from now"
MESSAGE="[${PREFIX}] `date +\"%Y/%m/%d %T\"`"
if [ $# -eq 0 ]
then
git add -u
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
else
then
if [ $1 != "--all" ]
then
git add $@
else
git add -u
git add .
fi
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
fi
#!/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
;;; git-now.el - Call "git now" command
(provide 'git-now)
(defun now ()
(interactive)
(call-process "git" nil "*git now*" nil "now")
(pop-to-buffer "*git now*" t nil)
(other-window -1)
(message "git now!"))
require 'formula'
class GitNow < GithubGistFormula
url 'https://gist.github.com/raw/1167062/03c52077ce8c7fb72537bdf9cbd50bd11f3a9d5c/git-now'
md5 '72a36ca8deb21b7cc26b8a8f5dc3e7be'
homepage 'https://gist.github.com/1167062'
end
#!/bin/sh
PREFIX="from now"
if [ ! "`git log --pretty=oneline $3 | head -n 1 | grep "${PREFIX}"`" ]
then
exit 0
else
echo "error: There are tmp log messages in the received objects." 1>&2
echo "error: Change these messages by 'git now --rebase'." 1>&2
exit 1
fi
@iwata
Copy link
Author

iwata commented Aug 25, 2011

--rebaseでログの全履歴じゃなく、引数で指定したブランチとの共通祖先をHEADから辿って、最も古いgit-now コミットからrebase するようにした

@iwata
Copy link
Author

iwata commented Aug 29, 2011

機能をわけて中途半端な状態…
なのでgithubに移行中。
でも本家さんからのforkじゃなくなってしまうのがもうしわけない。。

@iwata
Copy link
Author

iwata commented Sep 12, 2011

結構前にこっち→https://github.com/iwata/git-now に移動。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment