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

[PATCH 3/3] git --help COMMAND brings up the git-COMMAND man-page., take two

From
Andreas Ericsson <exon@op5.se>
Date
Nov 16, 2005, 00:23 UTC
Message-ID
<20051116002318.A46C55BF97@nox.op5.se>

It's by design a bit stupid (matching ^git rather than ^git-), so as to work with 'gitk' and 'git' as well.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 Documentation/git.txt |    2 ++
 git.c                 |   26 ++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

applies-to: 8a47ae8a825ab0e68ac46392bccd1ec16df39456 53e2024f89514d31a45936e3596e3d285dfd1bfe

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 91e9f9f..7cbfaf8 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -24,6 +24,8 @@ OPTIONS
 
 --help::
 	prints the synopsis and a list of available commands.
+	If a git command is named this option will bring up the
+	man-page for that command.
 
 --exec-path::
 	path to wherever your core git programs are installed.
diff --git a/git.c b/git.c
index d189801..4b7cbf6 100644
--- a/git.c
+++ b/git.c
@@ -160,6 +160,24 @@ static void prepend_to_path(const char *
 	setenv("PATH", path, 1);
 }
 
+static void show_man_page(char *git_cmd)
+{
+	char *page;
+
+	if (!strncmp(git_cmd, "git", 3))
+		page = git_cmd;
+	else {
+		int page_len = strlen(git_cmd) + 4;
+
+		page = malloc(page_len + 1);
+		strcpy(page, "git-");
+		strcpy(page + 4, git_cmd);
+		page[page_len] = 0;
+	}
+
+	execlp("man", "man", page, NULL);
+}
+
 int main(int argc, char **argv, char **envp)
 {
 	char git_command[PATH_MAX + 1];
@@ -199,8 +217,12 @@ int main(int argc, char **argv, char **e
 			usage(NULL, NULL);
 	}
 
-	if (i >= argc || show_help)
-		usage(exec_path, NULL);
+	if (i >= argc || show_help) {
+		if (i >= argc)
+			usage(exec_path, NULL);
+
+		show_man_page(argv[i]);
+	}
 
 	/* allow relative paths, but run with exact */
 	if (chdir(exec_path)) {
---
0.99.9.GIT
Next: H. Peter Anvin
Message 1 of 9 in “git --help COMMAND brings up the git-COMMAND man-page., take two”
  1. 3/3 git --help COMMAND brings up the git-COMMAND man-page., take twoAndreas Ericsson, Nov 16, 2005
  2. H. Peter AnvinNov 16, 2005
  3. Andreas EricssonNov 16, 2005
  4. git wrapper: basic fixes.Junio C Hamano, Nov 16, 2005
  5. Johannes SchindelinNov 16, 2005
  6. Junio C HamanoNov 16, 2005
  7. H. Peter AnvinNov 16, 2005
  8. Andreas EricssonNov 16, 2005
  9. H. Peter AnvinNov 16, 2005

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.