git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [TOY PATCH] git wrapper: show similar command names for an unknown command

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jun 7, 2008, 07:27 UTC
Message-ID
<20080607072721.GA3347@steel.home>
In-Reply-To
<alpine.DEB.1.00.0806050747000.21190@racer>
Johannes Schindelin, Thu, Jun 05, 2008 08:48:40 +0200:
Show 12 quoted lines
> A typical output would now look like this:
> 
> 	$ git reabse
> 	git: 'reabse' is not a git-command. See 'git --help'.
> 
> 	Did you mean one of these?
> 		rebase
> 		merge-base
> 		rev-parse
> 		remote
> 		rerere
> 

That's really cool :) And I find it useful (and already applied it to my tree). For me, it works like a simple reminder about what I was about to do. Helps when working on many things at the same time (typical typo: mrge. And your patch shows it as the first hit).

BTW, you probably want to restrict the number of lines output. For instance, "git ma" (am, printed correctly in the first line) lists around 30 commands, which scrolls clear a 25 line terminal and is a lot of output anyway. I tried it with at most 5 hints:

diff --git a/help.c b/help.c
index ac29225..765eed8 100644
--- a/help.c
+++ b/help.c
@@ -640,7 +640,7 @@ static int levenshtein_compare(const void *p1, const void *p2)
 
 void help_unknown_cmd(const char *cmd)
 {
-	int i, header_shown = 0;
+	int i, header_shown = 0, listed = 0;
 
 	fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);
 
@@ -667,6 +667,8 @@ void help_unknown_cmd(const char *cmd)
 			header_shown = 1;
 		}
 		fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
+		if (++listed >= 5)
+			break;
 	}
 
 	exit(1);
Previous: Wincent ColaiutaNext: Johannes Schindelin
Message 21 of 28 in “git wrapper: show similar command names for an unknown command”
  1. git wrapper: show similar command names for an unknown commandJohannes Schindelin, Jun 5, 2008
  2. Add subcommand "help" to the list of most commonly used subcommandsTeemu Likonen, Jun 5, 2008
  3. Johannes SchindelinJun 5, 2008
  4. Teemu LikonenJun 5, 2008
  5. 1/2 Add subcommand "help" to the list of most commonly used subcommandsTeemu Likonen, Jun 5, 2008
  6. 2/2 More informative short description for git-help.txtTeemu Likonen, Jun 5, 2008
  7. Johannes SchindelinJun 5, 2008
  8. Sverre RabbelierJun 5, 2008
  9. Teemu LikonenJun 5, 2008
  10. Junio C HamanoJun 5, 2008
  11. Pieter de BieJun 5, 2008
  12. Teemu LikonenJun 5, 2008
  13. Junio C HamanoJun 5, 2008
  14. David SymondsJun 6, 2008
  15. Wincent ColaiutaJun 5, 2008
  16. Sverre RabbelierJun 5, 2008
  17. Dirk SüsserottJun 5, 2008
  18. Johannes SchindelinJun 5, 2008
  19. Robin RosenbergJun 6, 2008
  20. Wincent ColaiutaJun 6, 2008
  21. Alex RiesenJun 7, 2008
  22. Johannes SchindelinJun 7, 2008
  23. Alex RiesenJun 7, 2008
  24. Junio C HamanoJun 7, 2008
  25. Johannes SchindelinJun 8, 2008
  26. Dirk SüsserottJun 8, 2008
  27. Junio C HamanoJun 8, 2008
  28. Johannes SchindelinJun 8, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.