From 1c62e436b787bb88054f0c06fc84f14987adb381 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Sat, 4 Feb 2012 13:51:43 -0800 Subject: [PATCH] changed git-squash(1) --- Readme.md | 15 ++++++++++----- bin/git-squash | 16 +++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Readme.md b/Readme.md index 47b1510..53baeb8 100644 --- a/Readme.md +++ b/Readme.md @@ -202,10 +202,6 @@ $ git commits-since yesterday TJ Holowaychuk - Fixed readme ``` -## git-squash [msg] - - Squashes the current branch into a single commit with the given `[msg]`. - ## git-count Output commit count: @@ -353,7 +349,7 @@ Create empty local branch `name`: $ git fresh-branch docs ``` -## git-graft <src-branch> <dest-branch> +## git-graft <src-branch> [dest-branch] Merge commits from `src-branch` into `dest-branch`. (`dest-branch` defaults to `master`.) @@ -362,6 +358,15 @@ $ git graft new_feature dev $ git graft new_feature ``` +## git-squash <src-branch> [msg] + +Merge commits from `src-branch` into the current branch as a _single_ commit. When `[msg]` is given `git-commit(1)` will be invoked with that message. This is useful when small individual commits within a topic branch are irrelevant and you want to consider the topic as a single change. + +```bash +$ git squash fixed-cursor-styling +$ git squash fixed-cursor-styling "Fixed cursor styling" +``` + ## git-changelog Populate a file whose name matches `change|history -i_` with commits diff --git a/bin/git-squash b/bin/git-squash index a780b84..71fc7ed 100755 --- a/bin/git-squash +++ b/bin/git-squash @@ -1,10 +1,12 @@ #!/bin/sh -# TODO: warn on master +src=$1 +msg=$2 -branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` -msg=${1-Squashed $branch} -git checkout -b squash-tmp master \ - && git merge --squash $branch \ - && git commit -m $msg \ - && git branch -M $branch \ No newline at end of file +test -z $src && echo "source branch required." && exit 1 + +git merge --squash $src && git branch -d $src + +if test -n $msg + git commit -a -m "$msg" +fi \ No newline at end of file