I am learning Git and have been unable to find any explanation of the flag syntax.
I'm not referring to the "bare double dashes"
--
which, as we know, indicate that what follows is not an option. I'm referring to various actual flags which sometimes have one dash, and sometimes have two.
git log -2 -p -U1 --graph
What is the difference between a flag with one dash and two dashes? What does the double dash indicate?
For example, the following two flags are identical, (according to this):
-q
--quiet
Why the different number of dashes? What if I put the wrong number?
By using the -a flag when committing you are telling Git to add all files that have been modified and then commit them.
When you use git on the command line you might have used the message flag ( -m ). It allows developers to define commit messages inline when calling git commit.
Perhaps the most common flag used with git commit is the -m flag. The -m flag, which stands for message, is used to add a commit message to a commit. When you use the git commit command without the -m flag, a text editor will be opened in which you can write a message, as we discussed earlier.
-u : The -u flag creates a tracking reference for every branch that you successfully push onto the remote repository. The local branch you push is automatically linked with the remote branch. This allows you to use commands such as git pull without any arguments.
My understanding is that git follows the 'standard' Linux convention for flags. That is:
git log -SFoo
, in which Foo
is a parameter to the -S
flag). These flags may or may not be abbreviated forms of other, longer flags.=
sign (e.g. git log --author=Peter
).This is the 'why': it is a convention which is embedded in the Linux world. Git comes from this world, so it follows the convention. The 'two dashes for a long flag, one for a short flag' rule should guide you as to how many dashes to use for a flag.
As for why there are duplicate short and long flags, such as --quiet
and -q
, it's just to provide the option of either mnemonic convenience or terseness. --quiet
is easier to remember, but -q
is quicker to type and mentally parse if you're used to it. For instance, I type git commit -m "...blah"
so frequently it would get on my nerves if I had to double the length of my command every time by entering git commit --message='...blah'
.
I haven't come across any git flags which behave differently given two dashes and one dash, so generally if you enter two dashes for a one-dash flag or vice versa, nothing irreparably bad will happen, git will just complain about your flags and do nothing.
Of course, git has a vast number of commands, each with a vast number of flags, so it is possible that there are exceptions to all these rules. They should generally hold though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With