{"id":4067,"date":"2022-12-20T17:39:18","date_gmt":"2022-12-20T20:39:18","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/gitcli-man7\/"},"modified":"2022-12-20T17:39:18","modified_gmt":"2022-12-20T20:39:18","slug":"gitcli-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/gitcli-man7\/","title":{"rendered":"GITCLI (man7)"},"content":{"rendered":"<h1 align=\"center\">GITCLI<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#ENHANCED OPTION PARSER\">ENHANCED OPTION PARSER<\/a><br \/> <a href=\"#NOTES ON FREQUENTLY CONFUSED OPTIONS\">NOTES ON FREQUENTLY CONFUSED OPTIONS<\/a><br \/> <a href=\"#GIT\">GIT<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">gitcli \u2212 Git command\u2212line interface and conventions<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">gitcli<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual describes the convention used throughout Git CLI.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Many commands take revisions (most often &#8220;commits&#8221;, but sometimes &#8220;tree\u2212ish&#8221;, depending on the context and command) and paths as their arguments. Here are the rules:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 Revisions come first and then paths. E.g. in <b>git diff v1.0 v2.0 arch\/x86 include\/asm\u2212x86<\/b>, <b>v1.0<\/b> and <b>v2.0<\/b> are revisions and <b>arch\/x86<\/b> and <b>include\/asm\u2212x86<\/b> are paths.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 When an argument can be misunderstood as either a revision or a path, they can be disambiguated by placing <b>\u2212\u2212<\/b> between them. E.g. <b>git diff \u2212\u2212 HEAD<\/b> is, &#8220;I have a file called HEAD in my work tree. Please show changes between the version I staged in the index and what I have in the work tree for that file&#8221;, not &#8220;show difference between the HEAD commit and the work tree as a whole&#8221;. You can say <b>git diff HEAD \u2212\u2212<\/b> to ask for the latter.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 Without disambiguating <b>\u2212\u2212<\/b>, Git makes a reasonable guess, but errors out and asking you to disambiguate when ambiguous. E.g. if you have a file called HEAD in your work tree, <b>git diff HEAD<\/b> is ambiguous, and you have to say either <b>git diff HEAD \u2212\u2212<\/b> or <b>git diff \u2212\u2212 HEAD<\/b> to disambiguate.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 Because <b>\u2212\u2212<\/b> disambiguates revisions and paths in some commands, it cannot be used for those commands to separate options and revisions. You can use <b>\u2212\u2212end\u2212of\u2212options<\/b> for this (it also works for commands that do not distinguish between revisions in paths, in which case it is simply an alias for <b>\u2212\u2212<\/b>).<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">When writing a script that is expected to handle random user\u2212input, it is a good practice to make it explicit which arguments are which by placing disambiguating <b>\u2212\u2212<\/b> at appropriate places.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell. These two mean different things:<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">$ git restore *.c <br \/> $ git restore *.c<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">The former lets your shell expand the fileglob, and you are asking the dot\u2212C files in your working tree to be overwritten with the version in the index. The latter passes the <b>*.c<\/b> to Git, and you are asking the paths in the index that match the pattern to be checked out to your working tree. After running <b>git add hello.c; rm hello.c<\/b>, you will <i>not<\/i> see <b>hello.c<\/b> in your working tree with the former, but with the latter you will.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 Just as the filesystem <i>.<\/i> (period) refers to the current directory, using a <i>.<\/i> as a repository name in Git (a dot\u2212repository) is a relative path and means your current repository.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Here are the rules regarding the &#8220;flags&#8221; that you should follow when you are scripting Git:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 it\u2019s preferred to use the non\u2212dashed form of Git commands, which means that you should prefer <b>git foo<\/b> to <b>git\u2212foo<\/b>.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 splitting short options to separate words (prefer <b>git foo \u2212a \u2212b<\/b> to <b>git foo \u2212ab<\/b>, the latter may not even work).<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 when a command\u2212line option takes an argument, use the <i>stuck<\/i> form. In other words, write <b>git foo \u2212oArg<\/b> instead of <b>git foo \u2212o Arg<\/b> for short options, and <b>git foo \u2212\u2212long\u2212opt=Arg<\/b> instead of <b>git foo \u2212\u2212long\u2212opt Arg<\/b> for long options. An option that takes optional option\u2212argument must be written in the <i>stuck<\/i> form.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 when you give a revision parameter to a command, make sure the parameter is not ambiguous with a name of a file in the work tree. E.g. do not write <b>git log \u22121 HEAD<\/b> but write <b>git log \u22121 HEAD \u2212\u2212<\/b>; the former will not work if you happen to have a file called <b>HEAD<\/b> in the work tree.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 many commands allow a long option <b>\u2212\u2212option<\/b> to be abbreviated only to their unique prefix (e.g. if there is no other option whose name begins with <b>opt<\/b>, you may be able to spell <b>\u2212\u2212opt<\/b> to invoke the <b>\u2212\u2212option<\/b> flag), but you should fully spell them out when writing your scripts; later versions of Git may introduce a new option whose name shares the same prefix, e.g. <b>\u2212\u2212optimize<\/b>, to make a short prefix that used to be unique no longer unique.<\/p>\n<h2>ENHANCED OPTION PARSER <a name=\"ENHANCED OPTION PARSER\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">From the Git 1.5.4 series and further, many Git commands (not all of them at the time of the writing though) come with an enhanced option parser.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Here is a list of the facilities provided by this option parser.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Magic Options<\/b> <br \/> Commands which have the enhanced option parser activated all understand a couple of magic command\u2212line options:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\u2212h<\/p>\n<p style=\"margin-left:17%;\">gives a pretty printed usage of the command.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">$ git describe \u2212h <br \/> usage: git describe [<options>] <commit\u2212ish>* <br \/> or: git describe [<options>] \u2212\u2212dirty<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">\u2212\u2212contains find the tag that comes after the commit <br \/> \u2212\u2212debug debug search strategy on stderr <br \/> \u2212\u2212all use any ref <br \/> \u2212\u2212tags use any tag, even unannotated <br \/> \u2212\u2212long always use long format <br \/> \u2212\u2212abbrev[=<n>] use <n> digits to display SHA\u22121s<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Note that some subcommand (e.g. <b>git grep<\/b>) may behave differently when there are things on the command line other than <b>\u2212h<\/b>, but <b>git subcmd \u2212h<\/b> without anything else on the command line is meant to consistently give the usage.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\u2212\u2212help\u2212all<\/p>\n<p style=\"margin-left:17%;\">Some Git commands take options that are only used for plumbing or that are deprecated, and such options are hidden from the default usage. This option gives the full list of options.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Negating options<\/b> <br \/> Options with long option names can be negated by prefixing <b>\u2212\u2212no\u2212<\/b>. For example, <b>git branch<\/b> has the option <b>\u2212\u2212track<\/b> which is <i>on<\/i> by default. You can use <b>\u2212\u2212no\u2212track<\/b> to override that behaviour. The same goes for <b>\u2212\u2212color<\/b> and <b>\u2212\u2212no\u2212color<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Aggregating short options<\/b> <br \/> Commands that support the enhanced option parser allow you to aggregate short options. This means that you can for example use <b>git rm \u2212rf<\/b> or <b>git clean \u2212fdx<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Abbreviating long options<\/b> <br \/> Commands that support the enhanced option parser accepts unique prefix of a long option as if it is fully spelled out, but use this with a caution. For example, <b>git commit \u2212\u2212amen<\/b> behaves as if you typed <b>git commit \u2212\u2212amend<\/b>, but that is true only until a later version of Git introduces another option that shares the same prefix, e.g. <b>git commit \u2212\u2212amenity<\/b> option.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Separating argument from the option<\/b> <br \/> You can write the mandatory option parameter to an option as a separate word on the command line. That means that all the following uses work:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ git foo \u2212\u2212long\u2212opt=Arg <br \/> $ git foo \u2212\u2212long\u2212opt Arg <br \/> $ git foo \u2212oArg <br \/> $ git foo \u2212o Arg<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">However, this is <b>NOT<\/b> allowed for switches with an optional value, where the <i>stuck<\/i> form must be used:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ git describe \u2212\u2212abbrev HEAD # correct <br \/> $ git describe \u2212\u2212abbrev=10 HEAD # correct <br \/> $ git describe \u2212\u2212abbrev 10 HEAD # NOT WHAT YOU MEANT<\/p>\n<h2>NOTES ON FREQUENTLY CONFUSED OPTIONS <a name=\"NOTES ON FREQUENTLY CONFUSED OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Many commands that can work on files in the working tree and\/or in the index can take <b>\u2212\u2212cached<\/b> and\/or <b>\u2212\u2212index<\/b> options. Sometimes people incorrectly think that, because the index was originally called cache, these two are synonyms. They are <b>not<\/b> \u2014 these two options mean very different things.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 The <b>\u2212\u2212cached<\/b> option is used to ask a command that usually works on files in the working tree to <b>only<\/b> work with the index. For example, <b>git grep<\/b>, when used without a commit to specify from which commit to look for strings in, usually works on files in the working tree, but with the <b>\u2212\u2212cached<\/b> option, it looks for strings in the index.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\u2022 The <b>\u2212\u2212index<\/b> option is used to ask a command that usually works on files in the working tree to <b>also<\/b> affect the index. For example, <b>git stash apply<\/b> usually merges changes recorded in a stash entry to the working tree, but with the <b>\u2212\u2212index<\/b> option, it also merges changes to the index as well.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>git apply<\/b> command can be used with <b>\u2212\u2212cached<\/b> and <b>\u2212\u2212index<\/b> (but not at the same time). Usually the command only affects the files in the working tree, but with <b>\u2212\u2212index<\/b>, it patches both the files and their index entries, and with <b>\u2212\u2212cached<\/b>, it modifies only the index entries.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">See also <b><font color=\"#0000FF\">https:\/\/lore.kernel.org\/git\/7v64clg5u9.fsf@assigned\u2212by\u2212dhcp.cox.net\/<\/font><\/b> <font color=\"#000000\">and<\/font> <b><font color=\"#0000FF\">https:\/\/lore.kernel.org\/git\/7vy7ej9g38.fsf@gitster.siamese.dyndns.org\/<\/font><\/b> <font color=\"#000000\">for further information.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Some other commands that also work on files in the working tree and\/or in the index can take <b>\u2212\u2212staged<\/b> and\/or <b>\u2212\u2212worktree<\/b>.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>\u2212\u2212staged<\/b> is exactly like <b>\u2212\u2212cached<\/b>, which is used to ask a command to only work on the index, not the working tree.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>\u2212\u2212worktree<\/b> is the opposite, to ask a command to work on the working tree only, not the index.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 The two options can be specified together to ask a command to work on both the index and the working tree.<\/font><\/p>\n<h2>GIT <a name=\"GIT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Part of the <b>git<\/b>(1) suite<\/font><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  gitcli \u2212 Git command\u2212line interface and conventions <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,1147,972],"class_list":["post-4067","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-gitcli","tag-man7"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4067"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4067\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}