This introduces a branch-stack mechanism to record branch switching in $GIT_DIR/BRANCH_STACK file. If you are switching to another branch and plan to come back to the original branch soon, add '--push' option to record your current branch. When you want to come back, 'git checkout --pop' will switch back to the branch recorded at the top of the stack, while popping it. Signed-off-by: しらいしななこ <nanako3@xxxxxxxxxxxxxx> --- git-checkout.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 41 insertions(+), 1 deletions(-) diff --git a/git-checkout.sh b/git-checkout.sh index f6d58ac..b53aea6 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -8,8 +8,10 @@ b= create a new branch started at <branch> l create the new branchs reflog track tells if the new branch should track the remote branch f proceed even if the index or working tree is not HEAD -m performa three-way merge on local modifications if needed +m perform a three-way merge on local modifications if needed q,quiet be quiet +push push the current branch to branch stack +pop come back to the previous branch by poping from branch stack " SUBDIRECTORY_OK=Sometimes . git-sh-setup @@ -27,6 +29,8 @@ newbranch= newbranch_log= merge= quiet= +push= +pop= v=-v LF=' ' @@ -49,6 +53,12 @@ while test $# != 0; do --track|--no-track) track="$1" ;; + --push) + push=1 + ;; + --pop) + pop=1 + ;; -f) force=1 ;; @@ -70,6 +80,27 @@ while test $# != 0; do shift done +if test -n "$pop" +then + if test $# != 0 + then + die "git checkout: --pop is incompatible with branch name" + fi + if test -n "$push" + then + die "git checkout: --pop and --push are incompatible" + fi + last=$(tail -n 1 "$GIT_DIR/BRANCH_STACK") + if test -z "$last" + then + die "git checkout: empty branch stack" + fi + sed -e '$d' <"$GIT_DIR/BRANCH_STACK" >"$GIT_DIR/BRANCH_STACK.new" + mv "$GIT_DIR/BRANCH_STACK.new" "$GIT_DIR/BRANCH_STACK" + set x "$last" + shift +fi + arg="$1" if rev=$(git rev-parse --verify "$arg^0" 2>/dev/null) then @@ -113,6 +144,11 @@ esac if test "$#" -ge 1 then + # Checking out a path out of the index or a commit + if test -n "$push" + then + die "git checkout: --push while not switching branches" + fi hint= if test "$#" -eq 1 then @@ -276,6 +312,10 @@ if [ "$?" -eq 0 ]; then else echo >&2 "Switched to${newbranch:+ a new} branch \"$branch\"" fi + if test -n "$push" + then + echo "$old_branch_name" >>"$GIT_DIR/BRANCH_STACK" + fi elif test -n "$detached" then old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'` -- 1.5.3.6 -- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/ ---------------------------------------------------------------------- Get a free email account with anti spam protection. http://www.bluebottle.com/tag/2 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html