简体   繁体   English

在Visual Studio 2013中创建新Git项目时出错

[英]Error on creating new Git project in Visual Studio 2013

I'm using Visual Studio 2013 with the MS Git plugin. 我正在使用带有MS Git插件的Visual Studio 2013。 I'm trying to add an existing project to source control on my machine. 我正在尝试在我的机器上添加一个现有项目来控制源代码。 The project is an empty project with one file. 该项目是一个包含一个文件的空项目。 The path to the project solution is C:\\_Projects\\HelloGitWorld\\HelloGitWorld.csproj - according to the git settings, I created the default repo location, but it doesn't seem to be storing the repo there (I tried this for other projects as well, and it created the repo in the same location as the solution). 项目解决方案的路径是C:\\_Projects\\HelloGitWorld\\HelloGitWorld.csproj - 根据git设置,我创建了默认的repo位置,但它似乎没有存储repo那里(我试过这个用于其他项目同样,它在与解决方案相同的位置创建了回购)。

So I basically right-clicked on the solution and chose 'add to source control'. 所以我基本上右键单击解决方案并选择“添加到源代码管理”。 This is simple enough, and as soon as I do that, I get: 这很简单,只要我这样做,我得到:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I realize you can do this through git bash as well, and I will eventually move onto that, but right now I just want to add a local repo for this. 我意识到你也可以通过git bash做到这一点,我最终将继续这样做,但是现在我只想为此添加一个本地回购。 Why won't it let me? 它为什么不让我? Where is this trying to create a path that is too long? 试图创建一条太长的路径在哪里?

Even though you create a project under your "default repo location" this does not mean a Git repo will be created for you. 即使您在“默认仓库位置”下创建项目,这也不意味着将为您创建Git仓库。 You need to create (or clone) a Git repository BEFORE creating a project/solution, or use the "Add to Source Control" option to ensure a new repo is created for you. 您需要在创建项目/解决方案之前创建(或克隆)Git存储库,或使用“添加到源代码管理”选项以确保为您创建新的存储库。

The "default repo location" is not a Git repo, and a solution folder is not (by default) a Git repo. “默认仓库位置”不是Git仓库,解决方案文件夹不是(默认情况下)Git仓库。

The real purpose of VS's "default git repo location" is so that VS tooling can locate any repositories you have cloned locally. VS的“默认git repo位置”的真正目的是使VS工具可以找到您在本地克隆的任何存储库。 It will search the immediate folder you specify and (I believe) any sub-folders. 它将搜索您指定的直接文件夹和(我相信)任何子文件夹。 Any folders recognized as Git repository roots will then appear in the list of Repos in the 'connect' page of Visual Studio UI. 任何被识别为Git存储库根目录的文件夹都将出现在Visual Studio UI的“连接”页面中的Repos列表中。

If you want to use the command-line this page on git-scm.com has a small snippet which shows how you could create a folder and initialize it as a git repo (locally.) Here is an example showing how to initialize your solution folder as a new, local Git repository from powershell (with msysgit installed): 如果你想使用命令行,git-scm.com上的这个页面有一个小片段,显示你如何创建一个文件夹并将其初始化为git repo(本地)。这是一个显示如何初始化你的解决方案的例子来自powershell的一个新的本地Git存储库文件夹(安装了msysgit ):

set-alias git "C:\Program Files (x86)\Git\bin\git.exe"
cd "C:\_Projects\HelloGitWorld\"
git init
git add .
git status

From there you can launch visual studio, load your project/solution and see that git integration is now working as intended. 从那里你可以启动visual studio,加载你的项目/解决方案,看看git集成现在正在按预期工作。 The same set of commands can be executed from a CMD shell, but you will probably have to specify the full path to git, or just use git bash (which may be obtuse for you if you're not accustomed to using unix shells.) 可以从CMD shell执行相同的命令集,但是您可能必须指定git的完整路径,或者只使用git bash(如果您不习惯使用unix shell,这可能会对您不利)。

If you don't want to use a command-line tool you can use Visual Studio Tools for Git and select "New.." from the "Connect to Team Projects" panel (thanks to Edward Thomson for pointing this out), or use a third party tool such as TortoiseGit . 如果您不想使用命令行工具,可以使用Visual Studio Tools for Git并从“Connect to Team Projects”面板中选择“New ..”(感谢Edward Thomson指出这一点),或者使用第三方工具,如TortoiseGit This will simplify the creation of a git repository without requiring you to understand how Git works, nor how to work with a command-line. 这将简化git存储库的创建,而无需了解Git的工作方式,也不了解如何使用命令行。 For most simply scenarios you can rely entirely on Visual Studio Tools for Git. 对于大多数简单的场景,您可以完全依赖于Visual Studio Tools for Git。 No need for anything third-party. 不需要任何第三方。

I use visualstudio.com and github.com for project hosting, as well as bare (private) repositories on a secure SAN at my home (since, in the end, you can't trust anyone anywhere with your private works. I don't care what people say.) You might find this article on saintsjd.com helpful in deciding if a bare repo is what you're really after, and this guide on stackoverflow to see how to create one yourself. 我使用visualstudio.com和github.com进行项目托管,以及在我家安全SAN上的裸(私人)存储库 (因为,最终,你无法信任任何人在你的私人作品。我不喜欢关心别人说的话。)你可能会发现saintsjd.com上的这篇文章有助于决定你真正追求的是什么,以及关于stackoverflow的本指南 ,看看如何自己创建一个。

Let me know if I can clarify anything, or if you need some examples. 如果我能澄清任何内容,或者您​​需要一些例子,请告诉我。

You've mentioned MS Git plugin - why you use it when VS2013 supports Git by default? 您已经提到过MS Git插件 - 为什么在默认情况下VS2013支持Git时使用它? I'm using standard VS2013 Git integration + Git for Windows to sync my solution with Bitbucket and it works fine. 我正在使用标准的VS2013 Git集成+ Git for Windows将我的解决方案与Bitbucket同步,它运行正常。 I also saw this strange default repo location setting, but all Git repos are actually placed inside .git folder under my solution when I use a solution context command " Add to source control... " (at this point you may create your Git repo from scratch). 我也看到了这个奇怪的默认仓库位置设置,但当我使用解决方案上下文命令“ 添加到源代码管理... ”时,所有Git仓库实际上都放在我的解决方案下的.git文件夹中(此时你可以创建你的Git仓库)从头开始)。 And actually .git folder + .gitattributes and .gitignore files are your local git repo which you may or may not sync with external hosted Git repo such as Bitbucket and Github. 实际上.git文件夹+ .gitattributes.gitignore文件是您的本地git .gitattributes ,您可能会或可能不会与外部托管的Git .gitattributes同步,如Bitbucket和Github。 If you want to remove Git binding for you solution just remove mentioned folder and files. 如果你想为你的解决方案删除Git绑定,只需删除提到的文件夹和文件。

As for the long path error you may check your actual solution path in Solution Explorer (select Solution root element and press F4). 对于长路径错误,您可以在解决方案资源管理器中检查实际的解决方案路径(选择解决方案根元素并按F4)。

Here are couple of links which may help you to get started: 以下是一些可以帮助您入门的链接:

It's worth mentioning here that if you're looking for a free hosted private Git repos then you might want to go on with Bitbucket (private repos are free for teams up to 5 people). 值得一提的是,如果你正在寻找一个免费的托管私人 Git回购,那么你可能想继续使用Bitbucket (私人回购对于最多5人的团队是免费的)。 If a small fee for private repos does not distract you then you might want to go on with Github which is the biggest Git repos hoster. 如果私人回购的小额费用不会分散您的注意力,那么您可能希望继续使用Github这是最大的Git回购主机。 Disclaimer: I'm not affiliated with Bitbucket and Github in any way, it's just a result of my personal investigation. 免责声明:我不以任何方式与Bitbucket和Github有关联,这只是我个人调查的结果。

Also I must admit that I'm not a fan of command line tools so my solution is good if you don't like them also. 此外,我必须承认,我不是命令行工具的粉丝所以如果你不喜欢它我的解决方案也很好。

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

相关问题 在Visual Studio 2013中为Web资产创建项目 - Creating a project for web assets in Visual Studio 2013 Visual Studio 2013错误创建EDMX文件 - Visual Studio 2013 error creating an EDMX file Visual Studio 2013错误创建Web API项目:元素下面的元素&lt;#text&gt; <Project> 无法识别 - Visual Studio 2013 error creating Web API project: The element <#text> beneath element <Project> is unrecognized 创建新项目Visual Studio时抛出错误 - Error thrown when creating a new project Visual Studio 在Visual Studio 2013中的“新建项目”对话框中缺少项目模板 - Missing project templates in “New Project” dialog box in Visual Studio 2013 Visual Studio 2013>新项目>未指定的错误(来自hresult的异常:0x80004005(e_fail)) - Visual Studio 2013 > New project > unspecified error (exception from hresult: 0x80004005 (e_fail)) 创建新表时Visual Studio 2013崩溃 - Visual studio 2013 crashing upon creating new table 是否可以在visual studio 2013 update 2中创建一个新的Windows Phone 8项目? - Is it possible to create a new windows phone 8 project in visual studio 2013 update 2? 无法在Visual Studio 2013中创建新的Web项目 - Unable to create a new web project in Visual Studio 2013 在Visual Studio 2013中创建安装程序 - Creating installer in Visual Studio 2013
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM