繁体   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