在 Visual Studio 中切换 Git 和 TFS 源代码管理

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

Switch between Git and TFS source control in visual studio

gitvisual-studio-2013tfs

提问by P.Brian.Mackey

I'm in a situation where I need to run both TFS and Git side by side. I will need to switch between the two. Git is installed and configure to run locally. TFS is run on a company server. How do I switch between the two environments in Visual Studio 2013?

我处于需要同时运行 TFS 和 Git 的情况。我需要在两者之间切换。Git 已安装并配置为在本地运行。TFS 在公司服务器上运行。如何在 Visual Studio 2013 中的两种环境之间切换?

I am open to switching to VS 2015 if git integration has improved.

如果 git 集成有所改进,我愿意切换到 VS 2015。

VS first detected Git and then switched over to that source control in "Team Explorer". I stumbled onto a way to switch to TFS (that I do not recall) and now I don't know how to switch back to Git.

VS 首先检测到 Git,然后在“团队资源管理器”中切换到该源代码管理。我偶然发现了一种切换到 TFS 的方法(我不记得了),现在我不知道如何切换回 Git。

If you care, I need to run Git side by side with TFS because I'm not allowed to create branches in TFS and there's no way I'm going to play around with commits in the Main trunk or manage N number of shelvesets. I'm going to use feature branches

如果您关心,我需要将 Git 与 TFS 并排运行,因为我不允许在 TFS 中创建分支,而且我无法在主干中处理提交或管理 N 个搁置集。我将使用功能分支

采纳答案by James Reed

If you want to use a TFS workspace and also use GIT then you can switch between them using Team Explorer. Hit the "plug" looking item at the top of the screen and you can switch between them there. The screen shot is from VS 2015 but the UI hasn't changed much from 2013

如果您想使用 TFS 工作区并同时使用 GIT,那么您可以使用团队资源管理器在它们之间切换。点击屏幕顶部的“插头”外观项目,您可以在它们之间切换。屏幕截图来自 VS 2015,但 UI 与 2013 年相比没有太大变化

Team Explorer

团队资源管理器

If you want to use git exclusively on your local machine and but push to TFS on the server then take a look at "git-TF"

如果您想在本地机器上专门使用 git,但要推送到服务器上的 TFS,请查看“ git-TF

You can clone your "Trunk" from TFS to a local git repo, work exclusively in git and use feature branches etc. When your code is ready to send back to Trunk then you can rebase and push i.e.

您可以将您的“Trunk”从 TFS 克隆到本地 git repo,在 git 中专门工作并使用功能分支等。当您的代码准备好发送回 Trunk 时,您可以重新设置并推送即

git-tf clone http://myserver:8080/tfs/mycollection $/TeamProjectA/Trunk

git-tf clone http://myserver:8080/tfs/mycollection $/TeamProjectA/Trunk

Make changes to the file in the Git repo

对 Git 存储库中的文件进行更改

git commit -a -m "commit one"(commit changes locally)

git commit -a -m "commit one"(在本地提交更改)

Make more changes

进行更多更改

git commit -a -m "commit two"

git commit -a -m "commit two"

git-tf pull --rebase

git-tf pull --rebase

git-tf checkin

git-tf checkin

回答by Tom

Not the most elegant solution, but it's straightforward and doesn't require 3rd party tools (assuming you already have a git shell)... I simply rename the .git folder to something else before starting studio and it'll use TFS. As soon as the solution is open, you can then rename the git folder back to ".git" and do anything git-related via a bash shell.

不是最优雅的解决方案,但它很简单,不需要 3rd 方工具(假设您已经有一个 git shell)......我只是在开始工作室之前将 .git 文件夹重命名为其他内容,它将使用 TFS。一旦解决方案打开,您就可以将 git 文件夹重命名回“.git”并通过 bash shell 执行任何与 git 相关的操作。

mv .git git
(open the solution in VS)
mv git .git

At this point, you can check in/out using TFS through IDE, and push/pull using git via the shell.

此时,您可以通过 IDE 使用 TFS 签入/签出,并通过 shell 使用 git 推/拉。

NOTE: One thing you'll have to watch out for is if new files are added from the git side (ie, via a git pull) Studio will list them under "Excluded Changes > Detected: ### adds" so you'll have to "Promote" them.

注意:您必须注意的一件事是,如果从 git 端添加新文件(即通过 git pull),Studio 会将它们列在“排除的更改 > 检测到:### 添加”下,以便您必须“促进”他们。

回答by Mike Gledhill

I had big problems trying to swap from GIT to TFS.

我在尝试从 GIT 切换到 TFS 时遇到了大问题。

Even attempting to open my project would just fail... none of the Solutions or its Projects would load.

即使尝试打开我的项目也会失败......解决方案或其项目都不会加载。

In the end, the only thing that worked was to manually move the (hidden) .git folder elsewhere. Only then could I open the Project via TFS, and see the friendly TFS context menu items ("Check in", rather than "Commit", etc)

最后,唯一有效的方法是手动将(隐藏的).git 文件夹移到别处。只有这样我才能通过 TFS 打开项目,并看到友好的 TFS 上下文菜单项(“签入”,而不是“提交”等)

回答by Arthur Bowers

I've been having this problem as at work we use TFS and I prefer to use git for local tracking of files. (Hopefully company is moving to git soon with some pushes from me...)

我在工作中一直遇到这个问题,我们使用 TFS,我更喜欢使用 git 进行文件的本地跟踪。(希望公司在我的推动下很快转向 git ......)

What I've found works is to make these aliases. alias degit="mv .git git" alias regit="mv git .git"

我发现有效的是制作这些别名。别名 degit="mv .git git" 别名 regit="mv git .git"

'degit' your repo as it were, before you launch VS2015 with TFS set as your source control, once it's all loaded up, 'regit' your repo. Seems to work well with me. Again though, I'm not currently using git for pushing to a remote. Still doing that using TFS.

在将 TFS 设置为源代码管理的情况下启动 VS2015 之前,'degit' 你的 repo,一旦它全部加载,'regit'你的 repo。似乎很适合我。不过,我目前没有使用 git 推送到远程。仍然使用 TFS 这样做。