Is it possible to shorten the git switch options?

Can git commit -a -m "commit msg" shrink to git commit -am "commit msg" and work as expected?

Basically, can options be set as short switches and let the last switch accept an argument?

+4
source share
3 answers

Yes.

Well-written Unix commands allow you to combine several one-letter options in one hyphen if none of the parameters except the last one in the group can accept an argument. Git is one of these well-written commands.

Many people who have not spent much time in the Unix shell do not realize this, and, unfortunately, sometimes these people finish working with command line utilities that do not use standard getopt(3) to analyze their options, and ultimately write their own An analyzer that prevents you from combining options in a standard way like this. Thus, there are some poorly written commands that do not allow this. Fortunately, Git is not one of these poorly written commands.

+5
source

Why don't you just give it a try?

 $ echo a > a; echo b > b $ git init Initialized empty Git repository in /home/me/tmp/a/.git/ $ git add ab $ git commit -m "hello" [master (root-commit) 184d670] hello 2 files changed, 2 insertions(+), 0 deletions(-) create mode 100644 a create mode 100644 bb > a; echo a > b $ git commit -am "other commit" [master 4ec9bb9] other commit 2 files changed, 2 insertions(+), 2 deletions(-) 

Journal:

 commit 4ec9bb943eb230923b4669ef6021124721cb9808 Author: me Date: Tue May 17 21:02:41 2011 +0200 other commit a | 2 +- b | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) commit 184d670b7862357cd8a898bfcaa79de271c09bd7 Author: me Date: Tue May 17 21:02:23 2011 +0200 hello a | 1 + b | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) 

So, all is well.

But: if you want an official to put this on git, check out the gitcli man page. It states:

splitting short options into separate words (prefer git foo -a -b to git foo -ab, the latter may not even work)

Thus, your mileage may vary, and a separate form is preferable to the git command.

+5
source

I assume the poster is asking because it does not have access to Git, given that it would be easier to try it than to post the question. To his credit, I really tried to find the canonical answer in the Git documentation (without the help of Google, mind you) and failed.

 $ git commit -am "yay" # On branch master nothing to commit (working directory clean) 

Remember that Git is written by Linus Torvalds, the creator of Linux. If someone strictly adheres to the POSIX rules , this is it ... You will notice that a double dash ( -- ) before marking the end parameters and the beginning of the arguments is also part of the Git syntax:

 git log -n 10 -- some/file.txt 

On the git log page:

 [--] <path>… Show only commits that affect any of the specified paths. To prevent confusion with options and branch names, paths may need to be prefixed with "-- " to separate them from options or refnames. 
+1
source

All Articles