summaryrefslogtreecommitdiff
path: root/builtin-checkout.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-10-18 19:34:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-10-18 19:34:56 (GMT)
commit619a644d6daef56d70aeca85514e2d281eb483a5 (patch)
tree8661f5c524f8e62450b5402ca16a2729820a3aff /builtin-checkout.c
parent46148dd7ea41de10fc784c247924f73ddb21121b (diff)
downloadgit-619a644d6daef56d70aeca85514e2d281eb483a5.zip
git-619a644d6daef56d70aeca85514e2d281eb483a5.tar.gz
git-619a644d6daef56d70aeca85514e2d281eb483a5.tar.bz2
"checkout A...B" switches to the merge base between A and B
When flipping commits around on topic branches, I often end up doing this sequence: * Run "log --oneline next..jc/frotz" to find out the first commit on 'jc/frotz' branch not yet merged to 'next'; * Run "checkout $that_commit^" to detach HEAD to the parent of it; * Rebuild the series on top of that commit; and * "show-branch jc/frotz HEAD" and "diff jc/frotz HEAD" to verify. Introduce a new syntax to "git checkout" to name the commit to switch to, to make the first two steps easier. When the branch to switch to is specified as A...B (you can omit either A or B but not both, and HEAD is used instead of the omitted side), the merge base between these two commits are computed, and if there is one unique one, we detach the HEAD at that commit. With this, I can say "checkout next...jc/frotz". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r--builtin-checkout.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index da04eed..fe7c858 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -689,7 +689,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
* case 3: git checkout <something> [<paths>]
*
* With no paths, if <something> is a commit, that is to
- * switch to the branch or detach HEAD at it.
+ * switch to the branch or detach HEAD at it. As a special case,
+ * if <something> is A...B (missing A or B means HEAD but you can
+ * omit at most one side), and if there is a unique merge base
+ * between A and B, A...B names that merge base.
*
* With no paths, if <something> is _not_ a commit, no -t nor -b
* was given, and there is a tracking branch whose name is
@@ -715,7 +718,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
if (!strcmp(arg, "-"))
arg = "@{-1}";
- if (get_sha1(arg, rev)) {
+ if (get_sha1_mb(arg, rev)) {
if (has_dash_dash) /* case (1) */
die("invalid reference: %s", arg);
if (!patch_mode &&