# Support "git cmd --help" syntax

5 messages from 2006-04-15 to 2006-04-19. Participants: Linus Torvalds, Junio C Hamano, Jakub Narebski.
Thread: https://gitlist.dev/t/3882

## Linus Torvalds, 2006-04-15 18:13

Subject: Support "git cmd --help" syntax
Message-ID: <Pine.LNX.4.64.0604151054380.3701@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0604151054380.3701%40g5.osdl.org

```

The "--help" argument is special, in that it is (along with "--version") 
in that is taken by the "git" program itself rather than the sub-command, 
and thus we've had the syntax "git --help cmd".

However, as anybody who has ever used CVS or some similar devil-spawn 
program, it's confusing as h*ll when options before the sub-command act 
differently from options after the sub-command, so this quick hack just 
makes it acceptable to do "git cmd --help" instead, and get the exact same 
result.

It may be hacky, but it's simple and does the trick.

Of course, this does not help if you use one of the non-builtin commands 
without using the "git" helper. Ie you won't be getting a man-page just 
because you do "git-rev-list --help". Don't expect us to be quite _that_ 
helpful.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/git.c b/git.c
index 78ed403..13c6d51 100644
--- a/git.c
+++ b/git.c
@@ -411,6 +411,12 @@ static void handle_internal_command(int 
 	};
 	int i;
 
+	/* Turn "git cmd --help" into "git help cmd" */
+	if (argc > 1 && !strcmp(argv[1], "--help")) {
+		argv[1] = argv[0];
+		argv[0] = cmd = "help";
+	}
+
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		struct cmd_struct *p = commands+i;
 		if (strcmp(p->cmd, cmd))

```

## Junio C Hamano, 2006-04-15 20:54

Subject: Re: Support "git cmd --help" syntax
Message-ID: <7vsloeef0k.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vsloeef0k.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.64.0604151054380.3701@g5.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> writes:

> However, as anybody who has ever used CVS or some similar devil-spawn 
> program, it's confusing as h*ll when options before the sub-command act 
> differently from options after the sub-command, so this quick hack just 
> makes it acceptable to do "git cmd --help" instead, and get the exact same 
> result.
>
> It may be hacky, but it's simple and does the trick.

Tried "git commit --help" with and without the patch?

I am not sure if we want to "help" migrants from CVS or some
similar program by shooting ourselves in the foot.

```

## Linus Torvalds, 2006-04-15 21:07

Subject: Re: Support "git cmd --help" syntax
Message-ID: <Pine.LNX.4.64.0604151402470.3701@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0604151402470.3701%40g5.osdl.org
In-Reply-To: <7vsloeef0k.fsf@assigned-by-dhcp.cox.net>

```


On Sat, 15 Apr 2006, Junio C Hamano wrote:
> 
> Tried "git commit --help" with and without the patch?

I get a usage message without the patch.

With the patch, I get the man-page.

IOW, I don't see your point.

I'd have expected that to be an improvement. You can always get the usage 
message with "git commit --huh?", so it's not like you've lost anything.

Now, if you have _not_ done

	make prefix=/usr/share install-doc

or similar, then yes, you get something less than helpful (along the lines 
of "No manual entry for git-commit"), and I agree that we could/should 
improve on that somehow. 

			Linus

```

## Junio C Hamano, 2006-04-16 01:24

Subject: Re: Support "git cmd --help" syntax
Message-ID: <7vd5fie2iv.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vd5fie2iv.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.64.0604151402470.3701@g5.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> writes:

> I'd have expected that to be an improvement. You can always get the usage 
> message with "git commit --huh?", so it's not like you've lost anything.

Fair enough.  I'd say I am convinced now.

```

## Jakub Narebski, 2006-04-19 21:40

Subject: Re: Support "git cmd --help" syntax
Message-ID: <e26anq$42t$1@sea.gmane.org>
URL: https://gitlist.dev/e/e26anq%2442t%241%40sea.gmane.org
In-Reply-To: <Pine.LNX.4.64.0604151402470.3701@g5.osdl.org>

```
Linus Torvalds wrote:

> [...] You can always get the usage
> message with "git commit --huh?", so it's not like you've lost anything.

Or "git commit --usage".

-- 
Jakub Narebski
Warsaw, Poland

```
