git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Detached-HEAD reminder on commit?
@ 2008-09-02 19:31 Pieter de Bie
  2008-09-02 19:43 ` Robin Rosenberg
                   ` (3 more replies)
  0 siblings, 4 replies; 67+ messages in thread
From: Pieter de Bie @ 2008-09-02 19:31 UTC (permalink / raw)
  To: Git Mailinglist

Sometimes I work on a detached HEAD and then forget about it. If I then create
some commits and checkout another branch, I have to dig through my reflog to
find the older commits. I know that "git commit" adds has a "Not currently on
any branch", but it's not very noticeable and also doesn't work when you
specify a commit message on the command line.

I suggest to add some extra output to the STDOUT after a commit if we're on a
detached HEAD. The quick patch below adds output like:

Vienna:git pieter$ ./git commit --allow-empty -m"test"
Created commit 6ce62c8b: test
You are on a detached head, so this commit has not been recorded in a branch.
If you don't want to lose this commit, checkout a branch and then run:
	git merge 6ce62c8bfcfb341106f3587d1c141c3955c2544c

Are there any comments to this / strong opinions against such a change?

- Pieter

diff --git a/builtin-commit.c b/builtin-commit.c
index ec65ac5..bfe25f9 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -845,6 +845,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 {
        struct rev_info rev;
        struct commit *commit;
+       unsigned char sha[20];
+       const char* head = resolve_ref("HEAD", sha, 0, NULL);
 
        commit = lookup_commit(sha1);
        if (!commit)
@@ -877,6 +879,15 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
                printf("%s\n", buf.buf);
                strbuf_release(&buf);
        }
+
+       /* Are we on a detached HEAD? */
+       if (!strcmp("HEAD", head))
+               printf("You are on a detached head, so this commit "
+                       "has not been recorded in a branch.\n"
+                       "If you don't want to lose this commit, checkout a "
+                       "branch and then run:\n"
+                       "       git merge %s\n", sha1_to_hex(sha1));
+
 }
 
 static int git_commit_config(const char *k, const char *v, void *cb)

^ permalink raw reply related	[flat|nested] 67+ messages in thread

end of thread, other threads:[~2008-10-04  2:15 UTC | newest]

Thread overview: 67+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-02 19:31 [RFC] Detached-HEAD reminder on commit? Pieter de Bie
2008-09-02 19:43 ` Robin Rosenberg
2008-09-02 20:24 ` Nicolas Pitre
2008-09-02 20:26 ` Matthieu Moy
2008-09-02 20:35   ` Nicolas Pitre
2008-09-02 20:39 ` Junio C Hamano
2008-09-02 21:05   ` Stephan Beyer
2008-09-02 21:39     ` Johan Herland
2008-09-02 21:44       ` Jeff King
2008-09-02 21:51         ` Jeff King
2008-09-03  7:45         ` Johan Herland
2008-09-03  8:07           ` Junio C Hamano
2008-09-03  9:47             ` Johan Herland
2008-09-03 13:15           ` Jeff King
2008-09-03 13:34             ` Jeff King
2008-09-03 13:46               ` Andreas Ericsson
2008-09-03 16:49               ` Daniel Barkalow
2008-09-03 18:07                 ` Jeff King
2008-09-03 19:36                   ` Junio C Hamano
2008-09-03 19:41                     ` Jeff King
2008-09-03 14:11             ` Wincent Colaiuta
2008-09-03 18:08               ` Jeff King
2008-09-03 15:16           ` Nicolas Pitre
2008-09-02 21:58       ` Junio C Hamano
2008-09-02 22:53       ` Nicolas Pitre
2008-09-04  4:50         ` Avery Pennarun
2008-09-04  5:31           ` Junio C Hamano
2008-09-05 23:43             ` Junio C Hamano
2008-09-02 21:51     ` Pieter de Bie
2008-09-02 22:11       ` Jakub Narebski
2008-09-02 22:50         ` Junio C Hamano
2008-09-02 22:58           ` Nicolas Pitre
2008-09-03 11:27       ` Pieter de Bie
2008-09-05 17:13         ` [PATCH] Builtin-commit: show on which branch a commit was added Pieter de Bie
2008-09-07  5:27           ` Junio C Hamano
2008-09-07  5:59             ` Junio C Hamano
2008-09-07 23:05               ` [PATCH 1/2] pretty.c: add %% format specifier Pieter de Bie
2008-09-07 23:05                 ` [PATCH 2/2] builtin-commit: show on which branch a commit was added Pieter de Bie
2008-09-21 10:42             ` [PATCH] Builtin-commit: " Jeff King
2008-09-29 20:09               ` Pieter de Bie
2008-09-29 22:44                 ` Jeff King
2008-09-30  6:13                   ` Andreas Ericsson
2008-09-30  6:16                     ` Jeff King
2008-09-30  9:45                       ` Andreas Ericsson
2008-09-30  9:52                       ` [PATCH] git commit: Reformat output somewhat Andreas Ericsson
2008-09-30  6:37                     ` [PATCH] Builtin-commit: show on which branch a commit was added Wincent Colaiuta
2008-09-30  7:09                       ` Jeff King
2008-09-30  9:59                         ` Andreas Ericsson
2008-10-01  3:14                           ` Jeff King
2008-10-01  8:13                             ` Andreas Ericsson
2008-10-01 15:10                               ` Shawn O. Pearce
2008-10-01 15:22                                 ` Andreas Ericsson
2008-10-01 15:25                                 ` Jeff King
2008-10-01 15:36                                   ` Shawn O. Pearce
2008-10-01 15:42                                     ` Jeff King
2008-10-01 15:44                                       ` Shawn O. Pearce
2008-10-01 21:06                                         ` [PATCH] git commit: Repaint the output format bikeshed (again) Andreas Ericsson
2008-10-01 22:06                                           ` Jeff King
2008-10-01 22:31                                             ` Jeff King
2008-10-02  5:40                                               ` Andreas Ericsson
2008-10-02 21:13                                                 ` Jeff King
2008-10-03  0:15                                                   ` Shawn O. Pearce
2008-10-03  4:24                                                     ` Jeff King
2008-10-03 14:09                                                       ` Shawn O. Pearce
2008-10-04  2:13                                                         ` Jeff King
2008-10-02  8:36                                             ` Wincent Colaiuta
2008-10-01 15:18                               ` [PATCH] Builtin-commit: show on which branch a commit was added Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).