git add 除了忽略 .gitignore 文件中的所有文件
我正在向一个没有源代码控制的项目添加源代码控制。问题是,有很多文件最初需要使用 .gitignore 文件添加到 git,但我不知道如何添加所有文件而不包含与 .gitignore 中的某些内容匹配的文件>.gitignore 文件。
git add *
上面的命令不会添加任何文件,因为它检测到被 .gitignore 忽略的文件。
git add -f *
上面的命令将添加所有文件,包括我希望忽略的文件。
那么,如何添加所有文件,同时仍然遵守 .gitignore 文件?
I am adding source control to a project that had none. The problem is that there are a lot of files to initially add to git with a .gitignore file, but I can't figure out how to add all files without including the files matching something in the .gitignore file.
git add *
The above command will not add any files because it detects files which are ignored by the .gitignore.
git add -f *
The above command will add all files including the files I wish to ignore.
So, how do I add all files while still adhering to the .gitignore file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为您的意思是
git add .
它将把所有未在.gitignore
中指定的文件添加到存储库中 - 您可以通过输入git status
bash 中的
.
通常表示该目录和所有其他递归目录,因此如果您从存储库的底层执行此操作,则应该添加所有文件。我通常的 git 流程是创建 .gitignore 文件并将项目文件添加到存储库中。我将在导入文件后输入
git status
来测试.gitignore
文件 - 如果我看到我添加的文件(例如仅 .php 或 .html) ,而不是 .mp3 或 .mov),然后您可以 git add . 来添加所有内容,并使用 git commit -m "initial commit" 来提交它们,您应该被设置。I think you mean
git add .
which will add all of the files to the repo that AREN'T specified in the.gitignore
- you can see these changes by typinggit status
The
.
in bash usually means this directory and all other directories recursively, so if you do this from the bottom level of your repo, you should add all of the files.My usual git flow is to create the
.gitignore
file and add the project files to the repo. I'll test the.gitignore
file by typinggit status
after importing the files - if I see the files that I've added (for example only .php or .html, NOT .mp3 or .mov), then you cangit add .
to add all, andgit commit -m "initial commit"
to commit them and you should be set.这将添加所有路径并忽略 .gitignore 中的匹配项
This will add all paths and ignore matches from .gitignore
尝试
git add .
(这意味着“添加当前目录及以下目录中的所有文件”)Try
git add .
(which means "add all files in the current directory and below")另一种选择是使用 Git 存储库的
exclude
文件。此文件的工作方式与.gitignore
文件类似,但不会提交到存储库。来自 Github 文档:
您可以使用此技术您不希望其他用户生成的本地生成的文件,例如由您的编辑器创建的文件。
使用您最喜欢的文本编辑器打开 Git 存储库根目录中名为
.git/info/exclude
的文件。您在此处添加的任何规则都不会被签入,并且只会忽略本地存储库的文件。.git/info/exclude
exclude
文件中,就像您在.gitignore
文件Another option is to use the Git repo's
exclude
file. This file works similar to a.gitignore
file but isn't committed to the repo.From the Github docs:
You can use this technique for locally-generated files that you don't expect other users to generate, such as files created by your editor.
Use your favorite text editor to open the file called
.git/info/exclude
within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository..git/info/exclude
exclude
file as you would the.gitignore
file我的仍然包含我告诉它忽略的文件,所以我这样做了......
我添加到 gitignore -> “.gitignore”
然后我尝试了“ git status ”,我想要忽略的文件被忽略了。
Mine still include files i told it to ignore, so i did this...
i added to gitignore -> " .gitignore "
then i tried " git status ", and the file i wanted ignored were ignored.
对于使用
Staging
/Unstaged
视图的用户,您可以通过添加-N
标志将所有内容添加到Unstaged
区域中, 像这样:For those using
Staged
/Unstaged
views, you can add everything into theUnstaged
area by adding the-N
flag, like this: