簡體   English   中英

什么是<pathspec>在 git 命令中?

[英]What's a <pathspec> in the git command?

我已經更新、修改和刪除了我的應用程序中的文件,現在我可以提交了。 這是狀態:

C:\G\ab\WebAdminApp>git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   WebAdminApp.csproj
        modified:   WebAdminApp.csproj.user
        modified:   app/admin/controllers/ContentController.ts
        deleted:    app/admin/interfaces/IEnumService.ts
        modified:   app/admin/interfaces/IHomeController.d.ts
        modified:   lib/pagedown/Markdown.Sanitizer.ts
        deleted:    lib/typings/global.ts
        modified:   package.json
        modified:   ../abilitest-admin.v12.suo

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        app/interfaces/IEnumService.d.ts
        app/interfaces/IUtilityService.d.ts
        ../npm-debug.log

未向提交添加任何更改(使用“git add”和/或“git commit -a”)

當我輸入:

git add . 

它給了我一條消息說:

C:\G\ab\WebAdminApp>git add .
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'WebAdminApp/app/admin/interfaces/IEnumService.ts' that are
removed from your working tree are ignored with this version of Git.

* 'git add --ignore-removal <pathspec>', which is the current default,
  ignores paths you removed from your working tree.

* 'git add --all <pathspec>' will let you also record the removals.

我希望我在本地 PC 上所做的一切都被提交,然后我希望 GITHUB 上的 master 反映這一點。

誰能解釋一下是什么意思我現在應該輸入什么,以便可以使用 git commit 提交所有更改? 對不起,我不清楚。 是目錄還是?

這個答案完全來自Git Pathspecs 和 How to Use Them 我沒有復制所有內容,因此請查看鏈接以進行更深入的挖掘


pathspec是 git 用於將 git 命令的范圍限制為存儲庫子集的機制。 如果您使用過很多 git,那么無論您是否知道,您都可能使用過pathspec 例如,在命令git add README.mdpathspecREADME.md 但是,它具有更多的細微差別和靈活性。

那么,為什么要了解pathspec呢? 由於它是許多命令的一部分,這些命令在理解pathspec變得更加強大。 使用git add ,您可以只添加單個目錄中的文件。 使用git diff ,您可以只檢查對擴展名為.scss文件名所做的更改。 您可以 git grep 除/dist目錄中的文件之外的所有文件。

文件或目錄

git add .      # add CWD (current working directory)
git add ..     # add parent directory and its subdirectories
git add src/   # add src/ directory
git add README # add only README directory

如果您執行ls -a ,它將列出所有文件和“目錄條目”,它將包括. ..更多見這里

通配符

git log '*.js' # logs all .js files in CWD and subdirectories
git log '.*'   # logs all 'hidden' files and directories in CWD
git log '*/.*' # logs all 'hidden' files and directories in subdirectories

最佳

top簽名告訴 git 匹配來自 git 存儲庫根目錄而不是當前工作目錄的模式。 您也可以使用簡寫:/而不是:(top)

git ls-files ':(top)*.js'
git ls-files ':/*.js' # shorthand

凱斯

icase簽名告訴 git 在匹配時不關心大小寫,例如這對於匹配jpg文件很有用,有時使用大寫擴展名JPG

git ls-files ':(icase)*.jpg'

排除

最后,還有“排除”魔術簽名( :!:^簡寫)。 例如,您可以搜索所有.js文件,同時排除.spec.js測試文件。

git grep 'foo' -- '*.js' ':(exclude)*.spec.js' # search .js files excluding .spec.js
git grep 'foo' -- '*.js' ':!*.spec.js' .       # shorthand for the same

來自Git 詞匯表

[路徑規范是一種模式] 用於限制 Git 命令中的路徑。

路徑規范用於“git ls-files”、“git ls-tree”、“git add”、“git grep”、“git diff”、“git checkout”等許多命令的命令行來限制范圍對樹或工作樹的某個子集的操作。

例如,命令git add :/**.ts將遞歸地將所有以.ts結尾的文件添加到索引中,從存儲庫的根目錄開始(尊重忽略文件的各種方式)。

如果您希望刪除的文件也從存儲庫中刪除,請執行git add --all . . 如果您不想在存儲庫中刪除它們,請執行git add --ignore-removal . .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM