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>
Nguyễn Thái Ngọc Duy committed
Mar 29, 2019 at 17:38 UTC
af9ded5b7007a4fa9844be7ac1c86f7a6ef2e56a
2 files changed
+25
-4
advice.c
+13
-4
@@ -191,13 +191,22 @@ void NORETURN die_conclude_merge(void)
191
void detach_advice(const char *new_name)
192
{
193
const char *fmt =
194
- _("Note: checking out '%s'.\n\n"
194
+ _("Note: checking out '%s'.\n"
195
+ "\n"
196
"You are in 'detached HEAD' state. You can look around, make experimental\n"
197
"changes and commit them, and you can discard any commits you make in this\n"
197
- "state without impacting any branches by performing another checkout.\n\n"
198
+ "state without impacting any branches by performing another checkout.\n"
199
+ "\n"
200
"If you want to create a new branch to retain commits you create, you may\n"
199
- "do so (now or later) by using -b with the checkout command again. Example:\n\n"
200
- " git checkout -b <new-branch-name>\n\n");
201
+ "do so (now or later) by using -b with the checkout command again. Example:\n"
202
+ "\n"
203
+ " git checkout -b <new-branch-name>\n"
204
+ "\n"
205
+ "Or undo this checkout with:\n"
206
+ "\n"
207
+ " git checkout -\n"
208
+ "\n"
209
+ "Turn off this advice by setting config variable advice.detachedHead to false\n\n");
210
211
fprintf(stderr, fmt, new_name);
212
}
t/t2020-checkout-detach.sh
+12
@@ -206,6 +206,12 @@ test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not as
206
207
git checkout -b <new-branch-name>
208
209
+ Or undo this checkout with:
210
+
211
+ git checkout -
212
+
213
+ Turn off this advice by setting config variable advice.detachedHead to false
214
+
215
HEAD is now at \$commit three
216
EOF
217
@@ -282,6 +288,12 @@ test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked
288
289
git checkout -b <new-branch-name>
290
291
+ Or undo this checkout with:
292
+
293
+ git checkout -
294
+
295
+ Turn off this advice by setting config variable advice.detachedHead to false
296
+
297
HEAD is now at \$commit... three
298
EOF
299