1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-18 01:56:15 +02:00

checkout: advice how to get out of detached HEAD mode

Detached HEAD mode is considered dangerous and confusing for newcomers
and we print a big block of warning how to move forward. But we should
also suggest the user the way to get out of it if they get into detached
HEAD by mistake.

While at there, I also suggest how to turn the advice off. This is
another thing I find annoying with advices and should be dealt with in a
more generic way. But that may require some refactoring in advice.c
first.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-03-29 17:38:58 +07:00 committed by Junio C Hamano
parent c2a8c1dd00
commit af9ded5b70
2 changed files with 25 additions and 4 deletions

View File

@ -191,13 +191,22 @@ void NORETURN die_conclude_merge(void)
void detach_advice(const char *new_name)
{
const char *fmt =
_("Note: checking out '%s'.\n\n"
_("Note: checking out '%s'.\n"
"\n"
"You are in 'detached HEAD' state. You can look around, make experimental\n"
"changes and commit them, and you can discard any commits you make in this\n"
"state without impacting any branches by performing another checkout.\n\n"
"state without impacting any branches by performing another checkout.\n"
"\n"
"If you want to create a new branch to retain commits you create, you may\n"
"do so (now or later) by using -b with the checkout command again. Example:\n\n"
" git checkout -b <new-branch-name>\n\n");
"do so (now or later) by using -b with the checkout command again. Example:\n"
"\n"
" git checkout -b <new-branch-name>\n"
"\n"
"Or undo this checkout with:\n"
"\n"
" git checkout -\n"
"\n"
"Turn off this advice by setting config variable advice.detachedHead to false\n\n");
fprintf(stderr, fmt, new_name);
}

View File

@ -206,6 +206,12 @@ test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not as
git checkout -b <new-branch-name>
Or undo this checkout with:
git checkout -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at \$commit three
EOF
@ -282,6 +288,12 @@ test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked
git checkout -b <new-branch-name>
Or undo this checkout with:
git checkout -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at \$commit... three
EOF