简体   繁体   English

在 Visual Studio 2013 中同时使用本地 Git 和(远程)TFS

[英]Using both local Git and (remote) TFS with Visual Studio 2013

I started work on some code locally and used Git (Git Gui and command-line) to manage it.我开始在本地处理一些代码并使用 Git(Git Gui 和命令行)来管理它。 I've now been asked to put the project into TFS "at corporate".我现在被要求将该项目“在公司”放入 TFS。 I can access TFS remotely using a VPN connection.我可以使用 VPN 连接远程访问 TFS。

The code is, to VS, a single solution with multiple projects.对于 VS,代码是具有多个项目的单一解决方案。 I successfully added the solution to TFS using VS, and it seemed to find all the projects and add their .csproj files and all the code to TFS source control.我使用 VS 成功地将解决方案添加到 TFS,它似乎找到了所有项目并将它们的 .csproj 文件和所有代码添加到 TFS 源代码管理中。

Later, when not connected to TFS (VPN off), I made a simple change and committed it to my local Git repository.后来,当没有连接到 TFS(VPN 关闭)时,我做了一个简单的更改并将其提交到我的本地 Git 存储库。 I have had nothing but frustration attempting to (connect to the VPN and) try to commit the change to TFS.我对尝试(连接到 VPN 并)尝试将更改提交到 TFS 感到非常沮丧。

  • I start Visual Studio.我启动 Visual Studio。
  • There is a "Team Explorer - Home" tab that has "Home | Offline" showing.有一个“团队资源管理器 - 主页”选项卡,其中显示“主页 | 离线”。
  • I check Tools / Options / Source Control and TFS is the current version control provider.我检查了工具/选项/源代码控制,TFS 是当前的版本控制提供程序。

So far so good.到现在为止还挺好。

  • I click the "plug" icon on the Team Explorer toolbar;我单击 Team Explorer 工具栏上的“plug”图标; it remembers the connection and now shows "Connect | Offline";它会记住连接,现在显示“连接 | 离线”;
  • Below is a line with a link "Select Team Projects..." and two sections with down-pointing triangles next to each.下面是一条带有“选择团队项目...”链接的行,以及两个部分,每个部分旁边都有向下的三角形。
    • One has the TFS server name (followed by (1));一个有TFS服务器名称(后跟(1)); under that is the name of the (only) "team project" where this is stored in TFS.下面是存储在 TFS 中的(唯一)“团队项目”的名称。
    • The other section has "Local Git Repositories (1)" and shows the name of the solution with the path to the solution directory next to it.另一部分有“本地 Git 存储库 (1)”,并显示解决方案的名称,旁边是解决方案目录的路径。
  • The tab title is "Team Explorer - Connect".选项卡标题是“团队资源管理器 - 连接”。
  • I double-click the name of the team project and the tab title changes to "Team Explorer - Home" and the screen shows "Home | {teamProjName}" and two sections.我双击团队项目的名称,选项卡标题更改为“团队资源管理器 - 主页”,屏幕显示“主页 | {teamProjName}”和两个部分。
    • One has "Project" with "Web Portal" and the usual "Pending Changes", "Source Control Explorer", etc icon sections below that;一个是带有“Web 门户”的“项目”和通常的“待定更改”、“源代码管理资源管理器”等位于其下方的图标部分;
    • And there's another section "Solutions" that has a line "Workspace: {workspaceName} | New... | "Open...";还有另一部分“解决方案”,有一行“工作区:{workspaceName} | 新建... |“打开...”;
    • Below that is the single solution file.下面是单个解决方案文件。
  • I double-click the solution name, and now the screen shows "Home | solutionName (Local)";我双击解决方案名称,现在屏幕显示“Home | solutionName (Local)”;
    • The Solutions section now has "Branch: master" (evidence of Git) and解决方案部分现在有“分支:大师”(Git 的证据)和
    • Tools / Options / Source Control says it's changed to the Microsoft Git Provider.工具/选项/源代码管理说它已更改为 Microsoft Git 提供程序。
  • If I change it back to TFS, it says "Home | Offline" and I have to click the "plug" icon again --如果我将其改回 TFS,它会显示“主页 | 离线”,我必须再次单击“插头”图标——

And I'm right back where I started, except that it says "Connect | {solutionName} (Local)"!我又回到了开始的地方,只是它说“Connect | {solutionName} (Local)”!

Opening the solution first doesn't help;首先打开解决方案没有帮助; when I connect to TFS the solution gets closed.当我连接到 TFS 时,解决方案将关闭。 Closing and opening VS just has it start in "VS knows about TFS, but you're offline" mode and opening the solution with TFS active makes it switch to the Git provider in (Local) mode.关闭和打开 VS 只是在“VS 知道 TFS,但您处于离线状态”模式下启动,并在 TFS 活动的情况下打开解决方案使其在(本地)模式下切换到 Git 提供程序。

I am very close to doing the registry hacks to disable the Microsoft Git Provider -- I've done my Git work using Git Gui and the commandline;我非常接近进行注册表黑客以禁用 Microsoft Git 提供程序——我已经使用 Git Gui 和命令行完成了我的 Git 工作; VS has not been involved. VS 没有参与。

Am I crazy?我疯了吗? I would have thought that "develop locally using Git, connect to TFS to sync with others" was a mainstream use case for VS.我会认为“使用 Git 在本地开发,连接到 TFS 以与其他人同步”是 VS 的主流用例。

Any assistance would be appreciated.任何援助将不胜感激。 Thanks.谢谢。

Visual Studio only sees git repositories if the .git folder is used as the store for the git repository.如果 .git 文件夹用作 git 存储库的存储,则 Visual Studio 仅会看到 git 存储库。 So, we can fake-out VS by using a different folder for the git store.因此,我们可以通过为 git 存储使用不同的文件夹来伪造 VS。

  • Rename the current .git folder to _git ( .git dir may be hidden)将当前的.git文件夹重命名为_git.git目录可能被隐藏)
  • Create a text file in that same folder called .git containing just the line gitdir: _git (make the file via command line: echo gitdir: _git>.git )在同一个名为.git文件夹中创建一个文本文件,其中只包含gitdir: _git (通过命令行创建文件: echo gitdir: _git>.git
  • Add _git to your .gitignore file_git添加到您的.gitignore文件中

Now when you launch VS it will not see that git repository and will use TFS instead.现在,当您启动 VS 时,它不会看到那个 git 存储库,而是会使用 TFS。

If the server is configured for TFVC and you have a local Git repo then you cant just push from local to tfs.如果服务器配置为 TFVC 并且您有本地 Git 存储库,那么您不能只是从本地推送到 tfs。 You have two options.你有两个选择。 You can:你可以:

1) You can create a new team project that is configured for Git and push as normal. 1)您可以创建一个新的团队项目,该项目为 Git 配置并照常推送。

2) you can use TF-Git to push from your local git repo to the TFVC server: http://www.microsoft.com/en-gb/download/details.aspx?id=30474 2) 您可以使用 TF-Git 从本地 git 存储库推送到 TFVC 服务器: http : //www.microsoft.com/en-gb/download/details.aspx?id= 30474

I switched to using mercurial for my local repository.我改用 mercurial 作为我的本地存储库。 This features no VS integration (needs external committing) but also no VS trouble.这没有 VS 集成(需要外部提交),但也没有 VS 问题。

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

相关问题 visual studio 2013如何记住远程git / tfs存储库和本地路径之间的映射? - How does visual studio 2013 remember the mapping between a remote git/tfs repository and a local path? 我可以在不使用TFS的情况下在Visual Studio 2013中使用GIT吗? - Can I use GIT with Visual Studio 2013 without using TFS? Visual Studio 2013 配置远程 Git 存储库 - Visual Studio 2013 Configure Remote Git Repo Visual Studio 2013 - Git - 获取远程分支 - Visual Studio 2013 - Git - Fetch remote branches 如何将现有的本地 git 存储库连接到 Visual Studio 2013 中的现有远程存储库? - How to connect an existing local git repository to its existing remote repository in Visual Studio 2013? 使用Git在线使用TFS的Visual Studio 2013:自动保存文件签入 - Visual Studio 2013 with TFS online using Git: Saving files checks-in automatically 使用 Visual Studio 2013 时,用于源代码控制的 TFVC(TFS 版本控制)和 Git 之间的最大区别是什么? - What are the big differences between TFVC (TFS Version Control) and Git for source control when using Visual Studio 2013? 在Visual Studio 2013中从TFS / Git获取标签版本 - Get labeled version from TFS/Git in Visual Studio 2013 Visual Studio错误推送到远程git-git-tfs迁移 - Visual Studio error pushing to remote git - git-tfs migration Git与Visual Studio 2013 - Git with Visual Studio 2013
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM