diff --git a/bin/git-squash b/bin/git-squash
index 249db5e..b6f412e 100755
--- a/bin/git-squash
+++ b/bin/git-squash
@@ -1,7 +1,26 @@
#!/usr/bin/env bash
+SQUASH_MSG=
+for arg in "$@"; do
+ case "$arg" in
+ --squash-msg)
+ SQUASH_MSG=1
+ ;;
+ *)
+ # set the argument back
+ set -- "$@" "$arg"
+ ;;
+ esac
+
+ shift
+done
+
src="$1"
msg="$2"
+if [[ -n "$msg" ]] && [[ -n "$SQUASH_MSG" ]]; then
+ >&2 echo "When commit message is given, --squash-msg is not allowed."
+ exit 1
+fi
is_branch() {
git show-ref --verify --quiet "refs/heads/$src"
@@ -35,11 +54,18 @@ prompt_continuation_if_squashing_master() {
squash_branch() {
prompt_continuation_if_squashing_master
+ if [ -n "$SQUASH_MSG" ]; then
+ base=$(git merge-base "$src" @)
+ msg=$(git log "$base".."$src" --format="%s%n%n%b" --no-merges --reverse)
+ fi
git merge --squash "$src" || exit 1 # quits if `git merge` fails
commit_if_msg_provided
}
squash_current_branch() {
+ if [ -n "$SQUASH_MSG" ]; then
+ msg=$(git log "$src"..@ --format="%s%n%n%b" --no-merges --reverse)
+ fi
git reset --soft "$src" || exit 1 # quits if `git reset` fails
commit_if_msg_provided
}
diff --git a/man/git-squash.1 b/man/git-squash.1
index ea7961f..6d73f4e 100644
--- a/man/git-squash.1
+++ b/man/git-squash.1
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "GIT\-SQUASH" "1" "October 2017" "" "Git Extras"
+.TH "GIT\-SQUASH" "1" "November 2019" "" "Git Extras"
.
.SH "NAME"
\fBgit\-squash\fR \- Import changes from a branch
.
.SH "SYNOPSIS"
-\fBgit\-squash\fR SYNOPSIS
-git-squash <source-branch|commit ref> [<commit-message>]git-squash [<--squash-messages>] <source-branch|commit ref> [<commit-message>]DESCRIPTION
@@ -93,6 +93,11 @@
A commit reference (has to be from the current branch) can also be used as the
first argument. A range of commits sha..HEAD will be squashed.
<--squash-msg>
+ +Commit the squash result with the concatenated squashed committed messages. + This option can not be used together with <commit-message>.
+<commit-message>
If commit-message is given, commit the squash result.
@@ -108,11 +113,12 @@ Squash commit -- not updating HEAD $ git commit -m "New commit without a real merge" $ git squash HEAD~3 "Commit message" +$ git squash --squash-msg @~3Written by Jesús Espino <jespinog@gmail.com>
+Written by Jesús Espino <jespinog@gmail.com>