将本地 Git 存储库发布到 Team Foundation Service

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14711796/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:07:25  来源:igfitidea点击:

Publish local Git repository to Team Foundation Service

visual-studiogittfsazure-devops

提问by basvo

About a week ago Git support was added to Visual Studio 2012 and Team Foundation Service. I've been playing around with it a bit and wanted to publish a local repository to my team project. It's described in step 2 on the Team Foundation Service website:

大约一周前,Visual Studio 2012 和 Team Foundation Service 中添加了 Git 支持。我一直在玩它,并想将本地存储库发布到我的团队项目。Team Foundation Service网站上的第 2 步对此进行了描述:

  • Publish your local Git repository into your new team project.
  • 将您的本地 Git 存储库发布到您的新团队项目中。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

Now I've been doing the exact same thing, but I don't get the "Publish to ..." context item. Could this be a bug or am I missing something?

现在我一直在做完全相同的事情,但我没有得到“发布到...”上下文项。这可能是一个错误还是我错过了什么?

enter image description here

在此处输入图片说明

采纳答案by ngm

I was having the same problem. I don't know why.

我遇到了同样的问题。我不知道为什么。

However, after a bit of playing around, I managed to get the following working. Disclaimer: can't guarantee this is actually the correct way to do it. It may bork things further. And whether it does the same as what the missing 'Publish' menu item is supposed to do, I have no idea. Use at your discretion...

但是,经过一番玩耍后,我设法使以下工作正常进行。免责声明:不能保证这实际上是正确的做法。它可能会使事情进一步恶化。并且它是否与缺少的“发布”菜单项的作用相同,我不知道。自行决定使用...

  • Get the url of your git repo in the project you set up in TFS.
  • Edit the .git/config file on your local repo.
    • Configure the origin remote to point to your TFS repo.
    • (note: if you already had an origin remote, you might want to rename that first to keep it)
  • 获取您在 TFS 中设置的项目中的 git repo 的 url。
  • 编辑本地存储库中的 .git/config 文件。
    • 将 origin 远程配置为指向您的 TFS 存储库。
    • (注意:如果你已经有一个 origin 遥控器,你可能想先重命名它以保留它)

e.g.

例如

[remote "origin"]
    url = https://user.visualstudio.com/DefaultCollection/_git/YourRepo
    fetch = +refs/heads/*:refs/remotes/origin/*
  • Open your solution in Visual Studio.
  • Edit a file.
  • Do a commit.
  • Do a push.
  • 在 Visual Studio 中打开您的解决方案。
  • 编辑文件。
  • 做一个提交。
  • 推一下。

This should hopefully push your local repo to your TFS remote as origin.

这应该有望将您的本地存储库作为源推送到您的 TFS 远程仓库。

From here things seem to be working for me -- the code is up in my TFS web interface at least, and I can push commits to it. I can add backlog items etc. I'm new to TFS though so not sure if it's actually all working as it should be.

从这里开始,事情似乎对我有用——代码至少在我的 TFS Web 界面中,我可以向它推送提交。我可以添加积压项目等。我是 TFS 的新手,所以不确定它是否真的按预期工作。

回答by Tim Rae

I was just having the same problem, and the answer by ngm didn't work; I had to do the opposite. The [remote "origin"] section was already in my .git/config file, however the project code wasn't uploaded to TFS.

我只是遇到了同样的问题,ngm 的回答没有用;我不得不做相反的事情。[remote "origin"] 部分已经在我的 .git/config 文件中,但是项目代码没有上传到 TFS。

To fix it I just deleted that section from the config file, then restarted Visual Studio and followed the official instructions.

为了修复它,我刚刚从配置文件中删除了该部分,然后重新启动 Visual Studio 并按照官方说明进行操作

回答by Josh McKearin

I had this same exact problem. I was able to resolve it by restarting Visual Studio completely, opening Team Explorer, then navigating to my local repo. I opened up my local .sln, then clicked on "Changes", "Commits" and it then had an area where I could Publish the project to a URL. I took that URL such as: https://myapps.visualstudio.com/DefaultCollection/_git/MySolutionand then clicked "Publish" (I had to do it twice.) I can now commit to the TFS and view my code online.

我有同样的问题。我能够通过完全重新启动 Visual Studio,打开团队资源管理器,然后导航到我的本地存储库来解决它。我打开我的本地 .sln,然后单击“更改”、“提交”,然后它有一个区域,我可以将项目发布到 URL。我使用了该 URL,例如:https: //myapps.visualstudio.com/DefaultCollection/_git/MySolution,然后单击“发布”(我必须执行两次。)我现在可以提交到 TFS 并在线查看我的代码。

回答by Michael Welch

I had the same issue. I had to delete all of my remotes in .git/config (not just origin) before the Publish option is available. Apparently, Microsoft assumes you would never even dream of using a different remote.

我遇到过同样的问题。在 Publish 选项可用之前,我必须删除 .git/config(不仅仅是 origin)中的所有遥控器。显然,微软认为你永远不会梦想使用不同的遥控器。

回答by Guillaume M

I had the same problem today, I was not understanding why this "Publish to..." menu didn't appear. I found that it's because you have to map one online repository to a local one, no more.

我今天遇到了同样的问题,我不明白为什么没有出现“发布到...”菜单。我发现这是因为您必须将一个在线存储库映射到本地存储库,仅此而已。

In your example, it seems Gittyup online is already mapped to Gittyup local, so you have to create a new Git project in the web interface, then you connect to it in VS, and then you can publish your local repository to the online one.

在您的示例中,Gittyup online 似乎已经映射到 Gittyup 本地,因此您必须在 Web 界面中创建一个新的 Git 项目,然后在 VS 中连接到它,然后您可以将本地存储库发布到在线存储库。

回答by JamesH

In the Team Explorer window find your repository under Local Git Repositories. Right click on the one you want to change and pick Open Command Prompt. Now type git remote -vand it should show you the remote name and the complete url for it. type git remote remove originassuming origin is the name of your remote repository. Then git remote add origin [url]replacing [url] with the actual url of your repository.

在 Team Explorer 窗口中,在 Local Git Repositories 下找到您的存储库。右键单击要更改的那个,然后选择打开命令提示符。现在输入git remote -v,它应该会显示远程名称和它的完整 url。类型git remote remove origin假设 origin 是您的远程存储库的名称。然后git remote add origin [url]将 [url] 替换为存储库的实际 url。

Now you should be able to push your master branch into the repository for your team project.

现在您应该能够将您的主分支推送到您的团队项目的存储库中。

回答by hawkeyecoder

I can confirm other answers, that the GIT repo cannot have any remotes listed or VS13 won't add it to the team project. I was using Atlassian tools Stash / Bitbucket / SourceTree and as soon as I closed VS13, removed all the remotes, reopenened VS13, opened the team project, and right clicked on my local GIT repo. The option "Publish to {teamProject}" was available and the .sln was then available by opening the team project.

我可以确认其他答案,即 GIT 存储库不能列出任何遥控器,否则 VS13 不会将其添加到团队项目中。我正在使用 Atlassian 工具 Stash/Bitbucket/SourceTree,一旦我关闭 VS13,删除所有遥控器,重新打开 VS13,打开团队项目,然后右键单击我的本地 GIT 存储库。可以使用“发布到 {teamProject}”选项,然后通过打开团队项目可以使用 .sln。

回答by niico

I found it helped to start a new solution and publish from there going step by step.

我发现它有助于开始一个新的解决方案并从那里一步一步地发布。

Once it's 'confused' itself it's best to start the process over. I got it working and never had to edit that file.

一旦它自己“感到困惑”,最好重新开始这个过程。我让它工作了,从来不需要编辑那个文件。

回答by Terence

I tried all of the above but the only way I could get it to work was to use git hub for windows.

我尝试了上述所有方法,但我可以让它工作的唯一方法是使用 git hub for windows。

To make that work you will need to set up alternate credentials. https://tfs.visualstudio.com/en-us/home/news/2012/aug-27/

要完成这项工作,您需要设置备用凭据。https://tfs.visualstudio.com/en-us/home/news/2012/aug-27/

回答by Ralph Roza

For submitting an existing local repository to TFS-Git:

将现有的本地存储库提交到 TFS-Git:

  • Create new project in TFS.
  • Using Git Extensions, select the local repository that you want to push to your new project in TFS.
  • Select the push arrow.
  • Select Manage remotes.
  • In URL, enter the location of your TFS project: https://[your site name].visualstudio.com/DefaultCollection/_git/[Your project name]
  • Save. Do you want to automatically configure push and pull? (I said yes.)
  • Close.
  • Select dropdown box for Remote - select the Remote URL you just saved.
  • Push.
  • 在 TFS 中创建新项目。
  • 使用 Git 扩展,选择要推送到 TFS 中的新项目的本地存储库。
  • 选择推动箭头。
  • 选择管理遥控器。
  • 在 URL 中,输入您的 TFS 项目的位置:https://[您的站点名称].visualstudio.com/DefaultCollection/_git/[您的项目名称]
  • 节省。是否要自动配置推拉?(我说是。)
  • 关闭。
  • 选择远程下拉框 - 选择您刚刚保存的远程 URL。
  • 推。

While setting up my account at TFS, I did set up an alternate credentials, though I am not sure if they were needed for this process.

在 TFS 设置我的帐户时,我确实设置了备用凭据,但我不确定此过程是否需要它们。

I am new to GIT and TFS, but this process allowed my to push two of my solutions, each with three projects into TFS. Also, within Git Extensions, I found that I could organize my local repositories into categories, which proved a convenient way to organize my projects into their solutions. I would like to do the same in TFS, too.

我是 GIT 和 TFS 的新手,但是这个过程允许我将我的两个解决方案推送到 TFS,每个解决方案都有三个项目。此外,在 Git Extensions 中,我发现我可以将我的本地存储库组织成类别,这证明这是一种将我的项目组织到其解决方案中的便捷方法。我也想在 TFS 中做同样的事情。