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

Sam*_*tar 8 git github

我已经在我的应用程序中更新,修改和删除了文件,现在我已准备好提交.这是状态:

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
Run Code Online (Sandbox Code Playgroud)

没有更改添加到提交(使用"git add"和/或"git commit -a")

当我进入:

git add . 
Run Code Online (Sandbox Code Playgroud)

它给了我一条信息:

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.
Run Code Online (Sandbox Code Playgroud)

我希望我在本地PC上所做的一切都得到提交,然后我希望GITHUB上的主人能够反映这一点.

有人可以解释它是什么意思 我现在应该输入什么,以便可以使用git提交来提交所有更改?对不起,我不清楚.是目录还是?

Hon*_*ney 8

这个答案完全来自Git Pathspecs 和 How to Use Them。我没有复制所有内容,因此请查看链接以进行更深入的挖掘


pathspec是 git 用于将 git 命令的范围限制为存储库子集的机制。如果您使用过很多 git,那么pathspec无论您是否知道,您都可能使用过。例如,在命令中git add README.mdpathspecREADME.md。但是,它具有更多的细微差别和灵活性。

那么,为什么要学习pathspecs呢?由于它是许多命令的一部分,因此了解pathspecs 后,这些命令会变得更加强大。使用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
Run Code Online (Sandbox Code Playgroud)

如果你这样做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
Run Code Online (Sandbox Code Playgroud)

最佳

top签名告诉混帐的模式从Git仓库,而不是当前工作目录的根目录匹配。您也可以使用简写:/而不是:(top).

git ls-files ':(top)*.js'
git ls-files ':/*.js' # shorthand
Run Code Online (Sandbox Code Playgroud)

凯斯

icase签名告诉混帐不关心匹配的情况下,当如这可能是有用的配套jpg文件,有时使用大写扩展名JPG

git ls-files ':(icase)*.jpg'
Run Code Online (Sandbox Code Playgroud)

排除

最后,还有“排除”魔术签名(:!或的简写:^)。例如,您可以搜索所有.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
Run Code Online (Sandbox Code Playgroud)


chw*_*arr 7

来自Git 词汇表

[路径规范是一种模式] 用于限制 Git 命令中的路径。

路径规范用于“git ls-files”、“git ls-tree”、“git add”、“git grep”、“git diff”、“git checkout”等许多命令的命令行来限制范围对树或工作树的某个子集的操作。

例如,该命令git add :/**.ts将递归地将所有.ts以存储库根目录开始的文件添加到索引中(尊重忽略文件的各种方式)。


Dav*_*sch 1

如果您希望删除的文件也从存储库中删除,请执行git add --all .。如果您不希望将它们从存储库中删除,请执行git add --ignore-removal .