]> git.phdru.name Git - git-wiki.git/blobdiff - pep-git.txt
Explain sticky options (git grep -O)
[git-wiki.git] / pep-git.txt
index 942aa34b002272f3714527a267b9f323d376b24f..5a4ec8000d94ef03b5430ee43e47d44ad6d7597b 100644 (file)
@@ -741,9 +741,30 @@ that's not an error, just a reminder to perform regular maintenance.
 Tips and tricks
 ===============
 
-TODO: sticky options; example: git grep -O.
-
-TODO: tricky options; example: git log -p3.
+Command-line options and arguments
+----------------------------------
+
+`git help cli
+<https://www.kernel.org/pub/software/scm/git/docs/gitcli.html>`_
+recommends not to combine short options/flags. Most of the times it
+works: ``git commit -av`` works perfectly, but there are situations
+when it doesn't. E.g., ``git log -p -5`` cannot be combined as ``git
+log -p5``.
+
+Some options have arguments, some even have default arguments. In that
+case the argument for such option must be spelled in sticky way:
+``-Oarg``, never ``-O arg`` because for an option that has a default
+argument the latter means "use default value for option ``-O`` and
+pass ``arg`` further to the option parser". For example, ``git grep``
+has an option ``-O`` that passes found files to a program; default
+program for ``-O`` is pager (ususally ``less``), but you can use your
+editor::
+
+    $ git grep -Ovim # but not -O vim
+
+BTW, there is a difference between running ``git grep -O`` and ``git
+grep -Oless`` - in the latter case ``git grep`` passes ``+/pattern``
+option to less.
 
 TODO: bash/zsh completion, bash/zsh prompt.
 https://git.kernel.org/cgit/git/git.git/tree/contrib/completion