如何将我现有的 Git 存储库推送到 Team Foundation Service
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15128541/
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
How can I push my existing Git repository to Team Foundation Service
提问by McKay
Microsoft now has support for Git repositories on their Team Foundation Service. I have an account on Team Foundation Service, and I'd like to push my existing Git repository to a project there.
Microsoft 现在在其 Team Foundation 服务上支持 Git 存储库。我在 Team Foundation Service 上有一个帐户,我想将我现有的 Git 存储库推送到那里的项目。
Whenever I try to do searches, I keep finding things like TFS-GIT, or GIT-TF. I'm pretty sure I don't want those, as I think those change to the Team Foundation Server model for code repositories, and that's not what I want.
每当我尝试进行搜索时,我都会不断找到诸如 TFS-GIT 或 GIT-TF 之类的东西。我很确定我不想要那些,因为我认为那些对代码存储库的 Team Foundation Server 模型的更改,这不是我想要的。
Specifically, I have an existing Git repository that I want to push to TFService.
具体来说,我有一个想要推送到 TFService 的现有 Git 存储库。
采纳答案by McKay
Okay, I was apparently overcomplicating this. Here's what I did.
好吧,我显然把这个问题复杂化了。这就是我所做的。
- Created a new project in TFService
- Connected to that project in Visual Studio
- Cloned that project in Visual Studio
git pull c:\source\oldGitProject
- 在 TFService 中创建了一个新项目
- 在 Visual Studio 中连接到该项目
- 在 Visual Studio 中克隆该项目
git pull c:\source\oldGitProject
That was it, it pulled all of the changes from the old location, and I could push that up to TFService easily.
就是这样,它从旧位置提取了所有更改,我可以轻松地将其推送到 TFService。
回答by VonC
"how do I push my existing git repository to TFService?"
“如何将我现有的 git 存储库推送到 TFService?”
Once you have declared a git repo on tfs.visualstudio.com (see below), add that git repo url to the remotes of your own local repo:
一旦你在 tfs.visualstudio.com 上声明了一个 git repo(见下文),将该 git repo url 添加到你自己本地 repo 的远程:
cd /path/to/local/repo
git remote add tfs url://tfs/git/repo
git push --mirror tfs
That will be enough to push the full history of your local repo back to that new upstream repo on TFS.
这足以将本地存储库的完整历史记录推回到 TFS 上的新上游存储库。
Again, the idea is to create a new empty repo on the upstream side (TFS), and to push your local repo to it.
同样,我们的想法是在上游端 (TFS) 创建一个新的空仓库,并将您的本地仓库推送到它。
(Original answer)
(原答案)
If I understand Scott Hanselman's blog post about it:
如果我了解Scott Hanselman 关于它的博客文章:
This Git support will require VS2012.2 (currently in preview) so you'll need to install that first, then get the VSIX. You'll be able to update both when VS2012.2 is released, and the Git VSIX will continue to update automatically via the VS Gallery.
It's a full source code provider for VS so you can use it to do most anything without leaving VS, or you can hang out at the command line and use it for a visual reminder as to the state of your repository.
For teams, you can go up to http://tfs.visualstudio.comand sign up for a account and get 5 users for free. You can choose either Git or Team Foundation Version Control (TFVC) as the source provider and use all the Team Foundation agile, scrum or other templates for your ALM tools
此 Git 支持将需要 VS2012.2(当前处于预览版),因此您需要先安装它,然后获取 VSIX。当 VS2012.2 发布时,您将能够更新两者,并且 Git VSIX 将继续通过 VS Gallery 自动更新。
它是 VS 的完整源代码提供程序,因此您可以在不离开 VS 的情况下使用它来做大多数事情,或者您可以在命令行中闲逛并使用它来直观地提醒您存储库的状态。
对于团队,您可以访问http://tfs.visualstudio.com并注册一个帐户并免费获得 5 个用户。您可以选择 Git 或 Team Foundation Version Control (TFVC) 作为源提供程序,并为您的 ALM 工具使用所有 Team Foundation 敏捷、Scrum 或其他模板
The registration process for a Git project is illustrated here, again pointing out that you need the “community technology preview” of the Git VSIXon top of a “community technology preview” of VS 2012 Update 2 (VS2012.2).
此处说明了 Git 项目的注册过程,再次指出您需要在VS 2012 Update 2 (VS2012.2)的“社区技术预览”的基础上进行 Git VSIX的“社区技术预览”。
回答by Rick Arthur
Some good answers above, but I found this even easier.
上面有一些很好的答案,但我发现这更容易。
- Create the local Git repository. (Or in my case, I converted my SVN repository to Git.)
- Go to visualstudio.com and create the new project, specifying Git as the source control.
- Click on the 'Code' menu option in the new project in VisualStudio.com.
The screen will show the exact Git command to push an existing repository, including the URL for your unique repository. All you have to do is copy and paste that command into your Git command prompt.
git clone <repository url>
- 创建本地 Git 存储库。(或者就我而言,我将我的 SVN 存储库转换为 Git。)
- 转到visualstudio.com 并创建新项目,指定Git 作为源代码管理。
- 在 VisualStudio.com 的新项目中单击“代码”菜单选项。
屏幕将显示推送现有存储库的确切 Git 命令,包括您唯一存储库的 URL。您所要做的就是将该命令复制并粘贴到您的 Git 命令提示符中。
git clone <repository url>
回答by rism
All we need do is change the server target url of the existing local solution/repo.
我们需要做的就是更改现有本地解决方案/存储库的服务器目标 url。
So:
所以:
- In the cloud (TFService), create a new project and get it's url.
On your local machine, open the existing solution/repo in Visual Studio and in the Package Management Console (PMC) run the following command
git remote set-url origin https://new.url.here
Using View>Team Explorer>Unsynched Commits push the existing solution / repo to the new project.
- 在云端 (TFService) 中,创建一个新项目并获取它的 url。
在本地计算机上,在 Visual Studio 中打开现有解决方案/存储库,并在包管理控制台 (PMC) 中运行以下命令
git remote set-url origin https://new.url.here
使用“视图”>“团队资源管理器”>“未同步提交”将现有解决方案/存储库推送到新项目。
This will push the local repo, including all previous commits, to the new TFS project in the cloud.
这会将本地存储库(包括所有以前的提交)推送到云中的新 TFS 项目。
Git command line FTW.
Git 命令行 FTW。
All this doing is updating the [url origin] attribute in the config file found in the .git folder, so you could just use notepad if you wanted to open and edit this file. IMHO this command is cleaner because you don't run the risk of accidentally editing some other setting nor do you have to leave VS.
所有这些都是在 .git 文件夹中找到的配置文件中更新 [url origin] 属性,所以如果你想打开和编辑这个文件,你可以使用记事本。恕我直言,此命令更清晰,因为您不会冒意外编辑其他设置的风险,也不必离开 VS。
Note: If the option to Push in step: 3 is disabled then you may have to perform another local commit in order to "dirty" the head of your source tree and thus enable the push command. Tho I'm sure there would be another git command to do this as well.
注意:如果在步骤 3 中推送选项被禁用,那么您可能需要执行另一个本地提交以“弄脏”源代码树的头部,从而启用推送命令。我敢肯定还会有另一个 git 命令来执行此操作。
回答by McKay
One of the blogs I found this morning linked this document:
我今天早上发现的一个博客链接了这个文件:
They appear to have an internal command called publish (which might be using the --mirror command that @VonC mentioned?)
他们似乎有一个名为 publish 的内部命令(可能正在使用 @VonC 提到的 --mirror 命令?)
I'm not sure if this works yet either.
我也不确定这是否有效。
回答by avivr
Ran into this problem today.
VonC's answer, adding TFS as a remote and using git push --mirror tfs
, worked for me.
However, it might be beneficial to mention some additional things about this.
今天遇到这个问题。VonC 的回答,将 TFS 添加为远程并使用git push --mirror tfs
,对我有用。但是,提及一些关于此的其他事情可能会有所帮助。
After the push, Visual Studio is still unable to identify that this local repo is connected to the Team Foundation Service in any way. So, you'll still need to select "Connect to Team Project..." and do a 'clone' using the interface. The repo from TFS will be cloned, with everything to just pushed. After this you'll be connected to TFS, and should be able to work normally in the clone.
Using '--mirror' will push all local references, potentially including some local branches that you don't really want to have in the central repo. If this is the case, after pushing with '--mirror', you should use
git push tfs :<branchname>
to delete a branch from TFS in order to avoid other people later pulling your local branches.Alternatively, instead of '--mirror', it should be possible to just push the desired refs into the TFS repo, just like you would any other git repo:
git push tfs <refspec>
. Since the TFS repo is still empty at this stage, a bunch of branch names one after the other should be enough as a<refspec>
. If using this method you could also use usegit push -u
, which will also make the branches you push into the empty repo tracking branches.
推送后,Visual Studio 仍然无法识别此本地存储库以任何方式连接到 Team Foundation Service。因此,您仍然需要选择“连接到团队项目...”并使用界面进行“克隆”。来自 TFS 的 repo 将被克隆,所有内容都将被推送。在此之后,您将连接到 TFS,并且应该能够在克隆中正常工作。
使用 '--mirror' 将推送所有本地引用,可能包括一些您不想在中央仓库中拥有的本地分支。如果是这种情况,在使用“--mirror”推送后,您应该使用
git push tfs :<branchname>
从 TFS 中删除一个分支,以避免其他人稍后拉取您的本地分支。或者,代替“--mirror”,应该可以将所需的引用推送到 TFS 存储库中,就像您将任何其他 git 存储库一样:
git push tfs <refspec>
。由于 TFS 存储库在此阶段仍然是空的,因此一堆分支名称一个接一个地作为<refspec>
. 如果使用此方法,您也可以使用 usegit push -u
,这也将使您推入空回购跟踪分支的分支。
EDIT:As mentioned in Edward Thomson's comment, cloning from TFS should be unnecessary if your original repo is configured to track a branch from the TFS remote. So git push -u <refspec>
should both push the repo to the empty TFS repo, and also allow the IDE to recognize the original local repo because it sets up tracking.
编辑:正如 Edward Thomson 的评论中提到的,如果您的原始存储库配置为跟踪来自 TFS 远程的分支,则不需要从 TFS 进行克隆。因此git push -u <refspec>
,既应该将存储库推送到空的 TFS 存储库,也应该允许 IDE 识别原始本地存储库,因为它设置了跟踪。