summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 86378b3)
raw | patch | inline | side by side (parent: 86378b3)
author | Junio C Hamano <junkio@cox.net> | |
Fri, 23 Jun 2006 08:37:02 +0000 (01:37 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 24 Jun 2006 08:11:19 +0000 (01:11 -0700) |
Some people tend to do many little commits on a topic branch,
recording all the trials and errors, and when the topic is
reasonably cooked well, would want to record the net effect of
the series as one commit on top of the mainline, removing the
cruft from the history. The topic is then abandoned or forked
off again from that point at the mainline.
The barebone porcelainish that comes with core git tools does
not officially support such operation, but you can fake it by
using "git pull --no-merge" when such a topic branch is not a
strict superset of the mainline, like this:
git checkout mainline
git pull --no-commit . that-topic-branch
: fix conflicts if any
rm -f .git/MERGE_HEAD
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
This however does not work when the topic branch is a fast
forward of the mainline, because normal "git pull" will never
create a merge commit in such a case, and there is nothing
special --no-commit could do to begin with.
This patch introduces a new option, --squash, to support such a
workflow officially in both fast-forward case and true merge
case. The user-level operation would be the same in both cases:
git checkout mainline
git pull --squash . that-topic-branch
: fix conflicts if any -- naturally, there would be
: no conflict if fast forward.
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
When the current branch is already up-to-date with respect to
the other branch, there truly is nothing to do, so the new
option does not have any effect.
This was brought up in #git IRC channel recently.
Signed-off-by: Junio C Hamano <junkio@cox.net>
recording all the trials and errors, and when the topic is
reasonably cooked well, would want to record the net effect of
the series as one commit on top of the mainline, removing the
cruft from the history. The topic is then abandoned or forked
off again from that point at the mainline.
The barebone porcelainish that comes with core git tools does
not officially support such operation, but you can fake it by
using "git pull --no-merge" when such a topic branch is not a
strict superset of the mainline, like this:
git checkout mainline
git pull --no-commit . that-topic-branch
: fix conflicts if any
rm -f .git/MERGE_HEAD
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
This however does not work when the topic branch is a fast
forward of the mainline, because normal "git pull" will never
create a merge commit in such a case, and there is nothing
special --no-commit could do to begin with.
This patch introduces a new option, --squash, to support such a
workflow officially in both fast-forward case and true merge
case. The user-level operation would be the same in both cases:
git checkout mainline
git pull --squash . that-topic-branch
: fix conflicts if any -- naturally, there would be
: no conflict if fast forward.
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
When the current branch is already up-to-date with respect to
the other branch, there truly is nothing to do, so the new
option does not have any effect.
This was brought up in #git IRC channel recently.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/merge-options.txt | patch | blob | history | |
git-commit.sh | patch | blob | history | |
git-merge.sh | patch | blob | history | |
git-pull.sh | patch | blob | history | |
git-reset.sh | patch | blob | history |
index 53cc35590debbb7e4d7dfae536be19e59d038560..182cef54be5963ff0f32a24329ca195607413e29 100644 (file)
not autocommit, to give the user a chance to inspect and
further tweak the merge result before committing.
+--squash::
+ Produce the working tree and index state as if a real
+ merge happened, but do not actually make a commit or
+ move the `HEAD`, nor record `$GIT_DIR/MERGE_HEAD` to
+ cause the next `git commit` command to create a merge
+ commit. This allows you to create a single commit on
+ top of the current branch whose effect is the same as
+ merging another branch (or more in case of an octopus).
-s <strategy>, \--strategy=<strategy>::
Use the given merge strategy; can be supplied more than
diff --git a/git-commit.sh b/git-commit.sh
index e74fe640b8acb87bef2cc118e87d8779c79f8786..9f49651cfdce101af3ba2c1980121d9ccea8a194 100755 (executable)
--- a/git-commit.sh
+++ b/git-commit.sh
elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
then
cat "$GIT_DIR/MERGE_MSG"
+elif test -f "$GIT_DIR/SQUASH_MSG"
+then
+ cat "$GIT_DIR/SQUASH_MSG"
fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
case "$signoff" in
fi
if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
then
- rm -f "$GIT_DIR/COMMIT_EDITMSG"
+ rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
run_status
exit 1
fi
false
fi
ret="$?"
-rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
+rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
if test -d "$GIT_DIR/rr-cache"
then
git-rerere
diff --git a/git-merge.sh b/git-merge.sh
index da5657eb40516430d0302eea2e15bac6fa699b55..fc25f8dda01ecf4733165308d9fb1fa80dffbe0c 100755 (executable)
--- a/git-merge.sh
+++ b/git-merge.sh
# Copyright (c) 2005 Junio C Hamano
#
-
-USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
+USAGE='[-n] [--no-commit] [--squash] [-s <strategy>]... <merge-message> <head> <remote>+'
. git-sh-setup
LF='
fi
}
+finish_up_to_date () {
+ case "$squash" in
+ t)
+ echo "$1 (nothing to squash)" ;;
+ '')
+ echo "$1" ;;
+ esac
+ dropsave
+}
+
+squash_message () {
+ echo Squashed commit of the following:
+ echo
+ git-log --no-merges ^"$head" $remote
+}
+
finish () {
test '' = "$2" || echo "$2"
- case "$merge_msg" in
- '')
- echo "No merge message -- not updating HEAD"
+ case "$squash" in
+ t)
+ echo "Squash commit -- not updating HEAD"
+ squash_message >"$GIT_DIR/SQUASH_MSG"
;;
- *)
- git-update-ref HEAD "$1" "$head" || exit 1
+ '')
+ case "$merge_msg" in
+ '')
+ echo "No merge message -- not updating HEAD"
+ ;;
+ *)
+ git-update-ref HEAD "$1" "$head" || exit 1
+ ;;
+ esac
;;
esac
-
- case "$no_summary" in
+ case "$1" in
'')
- git-diff-tree --stat --summary -M "$head" "$1"
+ ;;
+ ?*)
+ case "$no_summary" in
+ '')
+ git-diff-tree --stat --summary -M "$head" "$1"
+ ;;
+ esac
;;
esac
}
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
--no-summa|--no-summar|--no-summary)
no_summary=t ;;
+ --sq|--squ|--squa|--squas|--squash)
+ squash=t no_commit=t ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
no_commit=t ;;
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
?,1,"$1",*)
# If head can reach all the merge then we are up to date.
# but first the most common case of merging one remote.
- echo "Already up-to-date."
- dropsave
+ finish_up_to_date "Already up-to-date."
exit 0
;;
?,1,"$head",*)
done
if test "$up_to_date" = t
then
- echo "Already up-to-date. Yeeah!"
- dropsave
+ finish_up_to_date "Already up-to-date. Yeeah!"
exit 0
fi
;;
git-merge-$best_strategy $common -- "$head_arg" "$@"
;;
esac
-for remote
-do
- echo $remote
-done >"$GIT_DIR/MERGE_HEAD"
-echo "$merge_msg" >"$GIT_DIR/MERGE_MSG"
+
+if test "$squash" = t
+then
+ finish
+else
+ for remote
+ do
+ echo $remote
+ done >"$GIT_DIR/MERGE_HEAD"
+ echo "$merge_msg" >"$GIT_DIR/MERGE_MSG"
+fi
if test "$merge_was_ok" = t
then
diff --git a/git-pull.sh b/git-pull.sh
index bdd3939923bb905d561eb3ca88bda729cc93660d..aa8c2080927661cca281fca543dc5f0808f678e3 100755 (executable)
--- a/git-pull.sh
+++ b/git-pull.sh
LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
. git-sh-setup
-strategy_args= no_summary= no_commit=
+strategy_args= no_summary= no_commit= squash=
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
do
case "$1" in
no_summary=-n ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
no_commit=--no-commit ;;
+ --sq|--squ|--squa|--squas|--squash)
+ squash=--squash ;;
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
--strateg=*|--strategy=*|\
-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
esac
merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
-git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head
+git-merge $no_summary $no_commit $squash $strategy_args \
+ "$merge_name" HEAD $merge_head
diff --git a/git-reset.sh b/git-reset.sh
index 296f3b779b5889e4f9e69f994587d70503e8b25e..46451d0d64bdff2c0061d100c8d3b3bd38c21454 100755 (executable)
--- a/git-reset.sh
+++ b/git-reset.sh
;;
esac
-rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR"
+rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" "$GIT_DIR/SQUASH_MSG"