简体   繁体   English

git 在.gitignore文件中添加除了忽略文件之外的所有文件

[英]git add all except ignoring files in .gitignore file

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.问题是最初使用.gitignore文件将很多文件添加到 git 中,但我不知道如何添加所有文件而不包括.gitignore文件中匹配的文件。

git add *

The above command will not add any files because it detects files which are ignored by the .gitignore .上面的命令不会添加任何文件,因为它检测到被.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?那么,如何在仍然遵守.gitignore文件的同时添加所有文件?

I think you mean git add.我想你的意思是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 typing git status这会将所有文件添加到.gitignore中未指定的 repo - 您可以通过键入git 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.在 bash 通常表示此目录和所有其他目录递归,因此如果您从存储库的底层执行此操作,则应添加所有文件。

My usual git flow is to create the .gitignore file and add the project files to the repo.我通常的 git 流程是创建.gitignore文件并将项目文件添加到 repo。 I'll test the .gitignore file by typing git 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 can git add. I'll test the .gitignore file by typing git 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 can git add. to add all, and git commit -m "initial commit" to commit them and you should be set.添加所有,并git commit -m "initial commit"提交它们,你应该设置。

git add .

This will add all paths and ignore matches from.gitignore这将添加所有路径并忽略来自.gitignore 的匹配项

Try git add.试试git add. (which means "add all files in the current directory and below") (意思是“添加当前目录及以下目录中的所有文件”)

Another option is to use the Git repo's exclude file.另一种选择是使用 Git 存储库的exclude文件。 This file works similar to a .gitignore file but isn't committed to the repo.此文件的工作方式类似于.gitignore文件,但未提交到 repo。

From the Github docs :来自Github 文档

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.使用您喜欢的文本编辑器在 Git 存储库的根目录中打开名为.git/info/exclude的文件。 Any rule you add here will not be checked in, and will only ignore files for your local repository.您在此处添加的任何规则都不会被签入,并且只会忽略本地存储库的文件。

  1. In Terminal, navigate to the location of your Git repository在终端中,导航到 Git 存储库的位置
  2. Using your favorite text editor, open the file .git/info/exclude使用您喜欢的文本编辑器,打开文件.git/info/exclude
  3. Add rules to the exclude file as you would the .gitignore file像添加.gitignore文件一样向exclude文件添加规则

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.我的仍然包含我告诉它忽略的文件,所以我这样做了......我添加到 gitignore ->“.gitignore”然后我尝试了“git status”,我想要忽略的文件被忽略了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM