在 Visual Studio Code 中从 git 中排除文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32084281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exclude folder from git in Visual Studio Code
提问by Trewaters
I am using Visual Studio Code version 0.7.10. I want to use version control. I figured this was a good time to start teaching myself to use git. I have never used it before.
我使用的是 Visual Studio Code 0.7.10 版。我想使用版本控制。我认为这是开始自学使用 git 的好时机。我以前从未使用过它。
How do I make git ignore my "node_modules" folder? Every item in this folder is listed for possible commits and that is cluttering up my workspace. I don't want to upload all the packages. I figure whoever runs the package.json can do that on their own computer.
如何让 git 忽略我的“node_modules”文件夹?此文件夹中的每个项目都列出了可能的提交,这使我的工作区变得混乱。我不想上传所有的包。我认为运行 package.json 的人可以在自己的计算机上执行此操作。
Thought: I found under File > Preferences > User Settingsthat there is a configuration file called "settings.json" that will overwrite the default settings. I see a "Git configuration" in the default settings but I can't find any documentation on my possible options here. I would think I could do a "git.exclude" but where do I begin. This is only a guess at a solution. I am sure the real answer is something completely different.
思想:我在文件> 首选项> 用户设置下发现有一个名为“settings.json”的配置文件,它将覆盖默认设置。我在默认设置中看到了“Git 配置”,但在此处找不到有关我可能的选项的任何文档。我想我可以做一个“git.exclude”,但我从哪里开始。这只是对解决方案的猜测。我相信真正的答案是完全不同的。
I am looking for any documentation you could point me to. Thanks!
我正在寻找您可以指向我的任何文档。谢谢!
UPDATE: I made a change to the ".git/info/exclude" file and my Git repository view cleared up instantly. Here is a link that talks about the exclude file and why it worked for my VS Code editor. (https://help.github.com/articles/ignoring-files/)
更新:我对“.git/info/exclude”文件进行了更改,我的 Git 存储库视图立即清除。这是一个讨论排除文件以及为什么它适用于我的 VS Code 编辑器的链接。( https://help.github.com/articles/ignoring-files/)
采纳答案by Ahmed Eid
in git you can alyways use .gitignoreto make git ignore some files you can find documentation here : http://git-scm.com/docs/gitignore
在 git 中,您总是可以使用.gitignore使 git 忽略某些文件,您可以在此处找到文档:http: //git-scm.com/docs/gitignore
回答by Josh
You would make a .gitignore file in the base directory of your git repository and add any files or folders that you would like to ignore. In your case your file would contain
您将在 git 存储库的基本目录中创建一个 .gitignore 文件,并添加您想要忽略的任何文件或文件夹。在您的情况下,您的文件将包含
/node_modules/
Documentation: http://git-scm.com/docs/gitignore
回答by Philippe
Github maintain a repository containing .gitignore filesfor a lot of languages.
Github 维护一个存储库,其中包含许多语言的.gitignore 文件。
Hereis the one you need for Node...
这是您需要的Node ...
Or you could generate one (very useful if you use different technologies in the same repository) using the web site: http://gitignore.io
或者您可以使用网站生成一个(如果您在同一个存储库中使用不同的技术非常有用):http: //gitignore.io
Ps: Except if you've got really good reasons (exclude rules that you want to keep only for you), don't use .git/info/exclude
to ignore files but prefer to use and commit the .gitignore
file (to share it with all repository users).
Ps:除非你有很好的理由(排除你想只为你保留的规则),不要.git/info/exclude
用来忽略文件,而是更喜欢使用和提交.gitignore
文件(与所有存储库用户共享)。
回答by memeplex
You can use this setting:
您可以使用此设置:
"git.ignoredRepositories": []
which specifically does what you're asking. This won't pollute your .gitignore file if the only thing you want to do is to exclude a folder from vscode git but not from git itself. For example, this is useful if your home dir is under version control, since thousands of files would have to be ignored otherwise, which is hardly what you want.
它专门满足您的要求。如果您只想从 vscode git 中排除文件夹而不是从 git 本身中排除文件夹,则这不会污染您的 .gitignore 文件。例如,如果您的主目录受版本控制,这很有用,因为否则必须忽略数千个文件,这几乎不是您想要的。
回答by reza.cse08
Create a file with .gitignore& put the folder or file name which one you want to ignore.
使用.gitignore创建一个文件并输入您要忽略的文件夹或文件名。
to ignore everything below node_modules folder
忽略 node_modules 文件夹下的所有内容
echo node_modules/ > .gitignore
回答by David Alan Condit
This is an old solved question, but for anyone else who is still struggling with the accepted (and correct) answer, you literally need to add a file to your main (ie root) project folder called:
这是一个已解决的老问题,但对于仍在为接受(和正确)的答案而苦苦挣扎的其他人来说,您确实需要将一个文件添加到您的主(即根)项目文件夹中,名为:
.gitignore
.gitignore
If you add helloworld.gitignore it won't work. Or whywontthiswork.gitignore, etc. It must be .gitignore.
如果您添加 helloworld.gitignore 它将不起作用。或者whywontthiswork.gitignore等,必须是.gitignore。
Inside the file, type this text:
在文件中,输入以下文本:
/node_modules
/node_modules
Assuming your placement of the .gitignore file is at the same relative path of the node_modules folder, anything in node_modules will be excluded from change tracking.
假设您放置 .gitignore 文件的位置与 node_modules 文件夹的相对路径相同,则 node_modules 中的任何内容都将从更改跟踪中排除。
回答by LightCC
Adding to the other answers pointing you to make a .gitignore
file...
添加到指向您制作.gitignore
文件的其他答案中...
As a good starting point for any .gitignore
file, you can search at https://gitignore.io. Specific settings for 'VisualStudioCode' and various other tools and languages can be entered, and the site will generate a .gitignore file for you.
作为任何.gitignore
文件的良好起点,您可以在https://gitignore.io进行搜索。可以输入“VisualStudioCode”和各种其他工具和语言的特定设置,站点将为您生成一个 .gitignore 文件。
Additional points
加分
You can add a
.gitignore
to any folder to create entries specific to that folder and its nested folders as well.By default, Git will not save an empty folder. You can put an empty
.gitignore
file into a folder to force git to save it.
您可以将 a 添加
.gitignore
到任何文件夹以创建特定于该文件夹及其嵌套文件夹的条目。默认情况下,Git 不会保存空文件夹。您可以将一个空
.gitignore
文件放入文件夹中以强制 git 保存它。
回答by Rahul
There is a simple way to do this.
有一种简单的方法可以做到这一点。
git rm <file-name>
git commit -m '<message>'
git push
for folders,
对于文件夹,
git rm -r <folder-name>/*
git commit -m '<message>'
git push