mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
git-squash: add --squash-messages to concat commit messages into one.
This commit is contained in:
parent
f2934bd0bd
commit
1924eb9197
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <source\-branch|commit ref> [<commit\-message>]
|
||||
\fBgit\-squash\fR [<\-\-squash\-messages>] <source\-branch|commit ref> [<commit\-message>]
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
Produce the working tree and index state as if a real merge happened without the commit or merge marks\.
|
||||
|
|
@ -22,6 +22,12 @@ Branch to squash on the current branch\.
|
|||
<commit reference> A commit reference (has to be from the current branch) can also be used as the first argument\. A range of commits \fIsha\fR\.\.HEAD will be squashed\.
|
||||
.
|
||||
.P
|
||||
<\-\-squash\-msg>
|
||||
.
|
||||
.P
|
||||
Commit the squash result with the concatenated squashed committed messages\. This option can not be used together with <commit\-message>\.
|
||||
.
|
||||
.P
|
||||
<commit\-message>
|
||||
.
|
||||
.P
|
||||
|
|
@ -40,6 +46,7 @@ Squash commit \-\- not updating HEAD
|
|||
$ git commit \-m "New commit without a real merge"
|
||||
|
||||
$ git squash HEAD~3 "Commit message"
|
||||
$ git squash \-\-squash\-msg @~3
|
||||
.
|
||||
.fi
|
||||
.
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-squash</code> <source-branch|commit ref> [<commit-message>]</p>
|
||||
<p><code>git-squash</code> [<--squash-messages>] <source-branch|commit ref> [<commit-message>]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
|
|
@ -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 <var>sha</var>..HEAD will be squashed.</p>
|
||||
|
||||
<p> <--squash-msg></p>
|
||||
|
||||
<p> Commit the squash result with the concatenated squashed committed messages.
|
||||
This option can not be used together with <commit-message>.</p>
|
||||
|
||||
<p> <commit-message></p>
|
||||
|
||||
<p> If commit-message is given, commit the squash result.</p>
|
||||
|
|
@ -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 @~3
|
||||
</code></pre>
|
||||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Jesús Espino <<a href="mailto:jespinog@gmail.com" data-bare-link="true">jespinog@gmail.com</a>></p>
|
||||
<p>Written by Jesús Espino <<a href="mailto:jespinog@gmail.com" data-bare-link="true">jespinog@gmail.com</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
@ -125,7 +131,7 @@ $ git squash HEAD~3 "Commit message"
|
|||
|
||||
<ol class='man-decor man-foot man foot'>
|
||||
<li class='tl'></li>
|
||||
<li class='tc'>October 2017</li>
|
||||
<li class='tc'>November 2019</li>
|
||||
<li class='tr'>git-squash(1)</li>
|
||||
</ol>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ git-squash(1) -- Import changes from a branch
|
|||
|
||||
## SYNOPSIS
|
||||
|
||||
`git-squash` <source-branch|commit ref> [<commit-message>]
|
||||
`git-squash` [<--squash-messages>] <source-branch|commit ref> [<commit-message>]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
|
|
@ -20,6 +20,11 @@ git-squash(1) -- Import changes from a branch
|
|||
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.
|
||||
|
|
@ -35,6 +40,7 @@ git-squash(1) -- Import changes from a branch
|
|||
$ git commit -m "New commit without a real merge"
|
||||
|
||||
$ git squash HEAD~3 "Commit message"
|
||||
$ git squash --squash-msg @~3
|
||||
|
||||
## AUTHOR
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue