以下是從此處獲取的 Git 命令之一的描述:https ://git-scm.com/docs/git-branch 。據我了解,這個網站可以被視為官方檔案。對嗎?
我以git branch命令為例。我希望所有其他命令都遵循相同的規則。所以,這里是示例:
(1) git branch
[--color[=<when>] | --no-color] [--show-current]
[-v [--abbrev=<n> | --no-abbrev]]
[--column[=<options>] | --no-column] [--sort=<key>]
[--merged [<commit>]] [--no-merged [<commit>]]
[--contains [<commit>]] [--no-contains [<commit>]]
[--points-at <object>] [--format=<format>]
[(-r | --remotes) | (-a | --all)]
[--list] [<pattern>…?]
(2) git branch
[--track[=(direct|inherit)] | --no-track] [-f]
[--recurse-submodules] <branchname> [<start-point>]
(3) git branch
(--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
(4) git branch
--unset-upstream [<branchname>]
(5) git branch
(-m | -M) [<oldbranch>] <newbranch>
(6) git branch
(-c | -C) [<oldbranch>] <newbranch>
(7) git branch
(-d | -D) [-r] <branchname>…?
(8) git branch
--edit-description [<branchname>]
所以,我理解這個描述:
- 該
git branch命令有 8 個不相交的模式。正好 8 種模式。不是 6 或 7。 - 每個模式都明確列出了適用于該模式的所有鍵和引數。
- Git 根據命令列中的鍵決定應用哪種模式。我看到在上面的示例中,所有鍵僅以一種模式存在。沒有交叉點。
一切都會很棒,但是模式 1 和模式 2 中的所有鍵都是可選的。這意味著它們都可能丟失。在這種情況下,Git 將如何做出決定?
命令git branch abcd1234-whatever, 在模式 1 和模式 2 之間不明確。
我在這里錯過了其他東西嗎?
uj5u.com熱心網友回復:
對于第二種模式,并非所有鍵都是可選的。請注意,這<branchname>是在尖括號中,而不是方括號中。
根據經驗,以下列出了分支:
git branch
以下創建一個新分支:
git branch some_new_branch
該手冊明確解決了可能被誤解some_new_branch為現有分支的搜索模式的問題:
請注意,提供 時
<pattern>,您必須使用--list; 否則該命令可能被解釋為分支創建。
所以是的,一般規則存在歧義,但作者選擇接受它并提供明確的解決方法。具體來說,您必須明確地使用--list來指示模式 1 的可選位置引數與模式 2 的強制未標記引數。
話雖如此,我不會從手冊的那部分開始。雖然它完整且準確,但它并不試圖向您展示實際使用情況。相同的官方檔案有一個很好的教程部分,它將向您展示如何使用 git 作為工具。一旦您了解了基礎知識,命令手冊是搜索擴展功能的好地方。
查看 https://git-scm.com/docs 上的指南部分,例如https://git-scm.com/docs/gittutorial。與專案的作者和維護者撰寫的許多介紹性材料一樣,這些材料非常出色。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491539.html
標籤:混帐
上一篇:nodegit-如何知道提交是否為空(以避免推送空提交)
下一篇:抑制Bash腳本中的分離頭警告
