简体   繁体   English

从git存储库中删除目录和文件,并添加到忽略列表

[英]Remove directories and files from git repository and add to ignore list

I've got a .net solution directory (on OSX using a virtual machine) and just did a 我有一个.net解决方案目录(在OSX上使用虚拟机),只是做了一个

$ git add .
$ git commit

on the whole directory. 在整个目录上。

I forgot there were a number of file and directories I didn't want added, such as my _resharper directory, and the contents of my bin folder. 我忘了有一些我不想添加的文件和目录,比如我的_resharper目录,以及我的bin文件夹的内容。

So now, how do I first remove those directories and files from my local git repository without deleting them from my working copy? 那么现在,我如何首先从我的本地git存储库中删除这些目录和文件而不从我的工作副本中删除它们?

Additionally, how do I add said directories to an ignore list? 另外,如何将所述目录添加到忽略列表?

create a .gitignore file in the same directory as the repo. 在与repo相同的目录中创建.gitignore文件。 And put 并把

_resharper/
*file.cpp

*remember the slash after the directory name for folder names, no need asterisk *记住文件夹名称的目录名后面的斜杠,不需要星号

by the way, you will need to remove the folder, untrack and then put it back in if you already add and commited. 顺便说一下,如果你已经添加并提交,你将需要删除文件夹,未跟踪,然后将其重新放入。

You can learn more from here and here 您可以从这里这里了解更多信息

git reflog
git reset @HEAD{x} # x depends on what you see in reflog 
#edit .gitignore
#add line in gitignore 
#_resharper/

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

相关问题 如何忽略所有目录中的.dll文件 - How to ignore .dll files from all directories 我怎么能忽略 git 存储库中的 bin 和 obj 文件夹? - How could I ignore bin and obj folders from git repository? 要忽略的Git .Net文件 - Git .Net files to ignore 在迭代时从列表中删除/添加项目 - Remove/Add items to/from a list while iterating it 删除列表中的文件和目录以外的所有文件和目录 - Delete all files and directories except the ones in a list 使用C#从远程PC检索分区/目录/文件夹/文件的列表 - Retrieve list of partitions/directories/folders/files from remote PC using C# WinSCP .NET 程序集 - 在 GetFiles 之后删除文件(不是目录) - WinSCP .NET assembly - Remove files (not directories) after GetFiles 为什么在递归获取目录和文件时将其添加到列表中 <string> 只有目录而不是文件? - Why when getting directories and files recursive it's adding to the List<string> only directories and not files? 列出所有磁盘和所有目录上的所有文件,除了 C# .Net 中系统目录中的文件 - List all files on all disks and all directories except the files in system directories in C# .Net 从Visual Studio解决方案中删除项目后,如何从Git存储库中删除Visual Studio 2015项目? - How do I remove a Visual Studio 2015 project from my Git repository after I remove that project from my Visual Studio solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM