Skip to content

Commit

Permalink
checkout: make advice when reattaching the HEAD less loud
Browse files Browse the repository at this point in the history
When switching away from a detached HEAD with "git checkout", we give a
listing of the commits about to be lost, and then tell how to resurrect
them since 8e2dc6a (commit: give final warning when reattaching HEAD to
leave commits behind, 2011-02-18).

This is a good safety measure for people who are not comfortable with the
detached HEAD state, but the advice on how to keep the state you just left
was given even to those who set advice.detachedHead to false.

Keep the warning and informational commit listing, but honor the setting
of advice.detachedHead to squelch the advice.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed May 24, 2011
1 parent 8e2dc6a commit f807b3d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,14 +634,17 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
"Warning: you are leaving %d commit%s behind, "
"not connected to\n"
"any of your branches:\n\n"
"%s\n"
"If you want to keep them by creating a new branch, "
"this may be a good time\nto do so with:\n\n"
" git branch new_branch_name %s\n\n",
"%s\n",
lost, ((1 < lost) ? "s" : ""),
sb.buf,
sha1_to_hex(commit->object.sha1));
sb.buf);
strbuf_release(&sb);

if (advice_detached_head)
fprintf(stderr,
"If you want to keep them by creating a new branch, "
"this may be a good time\nto do so with:\n\n"
" git branch new_branch_name %s\n\n",
sha1_to_hex(commit->object.sha1));
}

/*
Expand Down

0 comments on commit f807b3d

Please sign in to comment.