gpt4 book ai didi

git - git 命令中的 是什么?

转载 作者:太空狗 更新时间:2023-10-29 13:02:48 26 4
gpt4 key购买 nike

我已经更新、修改和删除了我的应用程序中的文件,现在可以提交了。这是状态:

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 上的大师反射(reflect)这一点。

有人可以解释一下 是什么意思吗?我现在应该输入什么,以便所有更改都可以通过 git commit 提交?对不起,我不清楚。是目录还是?

最佳答案

这个答案完全来自Git Pathspecs and How to Use Them .我没有复制所有内容,所以请查看链接以进行更深入的研究


pathspec是 git 用于将 git 命令的范围限制为存储库的子集的机制。如果你用过很多 git,你可能用过 pathspec不管你知道与否。例如,在命令 git add README.md 中, pathspecREADME.md .但是,它具有更多的细微差别和灵 active 。

那么,为什么要了解 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

另请注意 git add命令需要 [<pathspec>...] . ...表示多次出现的可能性。所以你可以这样做:

git add /content /images

这将在两个目录下进行所有更改。

如果你做过 ls -a ,它将列出所有文件和“目录条目”,它将包括 ...有关更多信息,请参阅 here

通配符

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

git add '*/*.swift' # stages all 'swift' files

顶部

top signature 告诉 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 命令中的 <pathspec> 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com