CornSmith
CornSmith

Reputation: 2037

What are the dashes in git? Such as: -a -b -p

I know generally what they do, but where do they come from? Do they have a formal name? I've seen similar letters followed by dashes often in shell commands as well.

I couldn't turn up an answer after some quick searching, since I can't search for "-a" "-b" etc since the dash isn't picked up by search engines.

Edit: I found a search engine to look up things like this: symbolhound

Upvotes: 1

Views: 1659

Answers (4)

jcollado
jcollado

Reputation: 40424

Aside from what has been explained in other answers, please note that there's a git help comand that will provide information about the options for all subcommands.

For example, in the output for git help commit you'll see the following:

OPTIONS

  -a, --all
      Tell the command to automatically stage files that have been modified and deleted, but new files you have not
      told git about are not affected.

Upvotes: 0

Owen
Owen

Reputation: 39366

The dashes mark options to the command. So, -a is one option, and -b is another option.

The reason there is a dash is so that you and the command know that it is an option. So for example,

git commit --amend main.c

The dashes before --amend makes it clear that --amend is an option, whereas main.c has no dashes, so it is a regular argument.

And this is the way it is with almost all shell commands. See a man page for more details.

Upvotes: 0

Chris Eberle
Chris Eberle

Reputation: 48795

Those are called switches. They are extremely common on the command line. Most open source software (such as git) use libraries like getopt to read these. The format is very predictable:

  • -a [VALUE] (for single letter switches)
  • --name[=VALUE] (for spelled out switches)

In both of these cases VALUE may or may not be required depending on the switch. In your example they're not used. Reading the man pages or running command --help will usually tell you what switches are supported.

Upvotes: 1

Daniel Pittman
Daniel Pittman

Reputation: 17232

They are frequently called options; programming tools like getopt and popt parse them in a more or less standard way. You will run into them all over the place in Unix, such as the standard ls -l option to list in "long form" rather than short form.

The point of the - is not that it is anything but an arbitrary-but-conventional character that rarely occurs in, for example, at the start of the names of files, or branches, so is relatively easy to distinguish between "behave differently" and "operate on this thing" in the tool.

Upvotes: 1

Related Questions