在Visual Studio 2013中创建新的Git项目时出错 [英] Error on creating new Git project in Visual Studio 2013

查看:212
本文介绍了在Visual Studio 2013中创建新的Git项目时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2013和MS Git插件。我试图在我的机器上添加一个现有的项目来源控制。该项目是一个带有一个文件的空项目。项目解决方案的路径是 C:\_Projects\HelloGitWorld\HelloGitWorld.csproj - 根据git设置,我创建了默认的回购点,但它没有似乎并没有在那里存储回购协议(我也为其他项目尝试过,并且它在与解决方案相同的位置创建了回购协议)。

所以我基本上右键单击该解决方案并选择添加到源代码管理。这很简单,只要我这样做,我会得到:

 指定的路径,文件名或两者都是太长。完全限定的文件名必须少于260个字符,且目录名称必须少于248个字符。 

我意识到你也可以通过git bash来做到这一点,而且我最终会走到这一步,但现在我只想添加一个本地回购。为什么它不让我?

解决方案

尽管您在默认回购地点下创建了一个项目这并不意味着Git会为您创建回购协议。 您需要在创建项目/解决方案之前创建(或克隆)Git存储库,或使用添加到源代码管理选项来确保为您创建新的存储库。



默认回购库位置不是Git回购库,解决方案文件夹不是(默认情况下)Git回购库。

VS的默认git仓库位置的真正目的是让VS工具可以找到你本地克隆的任何仓库。它将搜索您指定的立即文件夹和(我相信)任何子文件夹。任何识别为Git存储库根目录的文件夹将出现在Visual Studio UI'连接'页面的Repos列表中。



如果您想使用命令行此页面上的git-scm.com 有一个小其中显示了如何创建一个文件夹并将其初始化为一个git仓库(本地)。下面是一个示例,展示了如何使用powershell将解决方案文件夹初始化为新的本地Git仓库( msysgit ):

  set-alias gitC:\程序文件(x86)\Git\bin\git.exe
cdC:\_Projects\HelloGitWorld\
git init
git add。
git status

从那里您可以启动visual studio,加载您的项目/解决方案并查看该git集成现在按预期工作。可以从CMD shell执行相同的一组命令,但是你可能需要指定git的完整路径,或者只使用git bash(如果你不习惯使用unix shell,那么可能会对你不利)。



如果您不想使用命令行工具,则可以使用 Visual Studio Tools for Git ,然后从Connect to Team Projects面板中选择New ..(感谢爱德华汤姆森指出这一点),或使用第三方工具,如 TortoiseGit 。这将简化创建git存储库的过程,而不需要您了解Git的工作方式,以及如何使用命令行。对于大多数简单场景,您完全可以依赖Visual Studio Tools for Git。不需要任何第三方。



我使用visualstudio.com和github.com进行项目托管,以及裸机(私人)存储库上的安全SAN在我家里(因为最后,你不能信任任何与你的私人作品在任何地方的人,我不在乎人们说什么。)你可能会发现这篇关于saintsjd.com的文章有助于决定裸露的回购是否是真的在之后,和这个指南在stackoverflow 看到如何创建一个你自己。

让我知道我是否可以澄清任何事情,或者如果你需要一些例子。


I'm using Visual Studio 2013 with the MS Git plugin. 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).

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. 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. 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.

The "default repo location" is not a Git repo, and a solution folder is not (by default) a Git repo.

The real purpose of VS's "default git repo location" is so that VS tooling can locate any repositories you have cloned locally. 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.

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):

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. 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.)

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. 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. For most simply scenarios you can rely entirely on 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.

Let me know if I can clarify anything, or if you need some examples.

这篇关于在Visual Studio 2013中创建新的Git项目时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆