在 Visual Studio 中使用 Git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/507343/
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
Using Git with Visual Studio
提问by Herb Caudill
As a long-time Visual SourceSafeuser (and hater) I was discussing switching to SVNwith a colleague; he suggested using Gitinstead. Since, apparently, it can be used as peer-to-peer without a central server (we are a 3-developer team).
作为Visual SourceSafe的长期用户(和仇恨者),我正在与一位同事讨论切换到SVN;他建议改用Git。因为,显然,它可以在没有中央服务器的情况下用作点对点(我们是一个由 3 个开发人员组成的团队)。
I have not been able to find anything about tools that integrate Git with Visual Studio, though - does such a thing exist?
但是,我找不到有关将 Git 与 Visual Studio 集成的工具的任何信息 - 这样的东西存在吗?
What are the technologies available for using Git with Visual Studio? And what do I need to know about how they differ before I begin?
有哪些技术可用于将 Git 与 Visual Studio 结合使用?在我开始之前,我需要了解它们的不同之处吗?
采纳答案by Jon Rimmer
In Jan 2013, Microsoft announcedthat they are adding full Git support into all their ALM products. They have published a pluginfor Visual Studio 2012 that adds Git source control integration.
2013 年 1 月,Microsoft宣布他们将在所有 ALM 产品中添加对 Git 的完整支持。他们为 Visual Studio 2012发布了一个插件,该插件添加了 Git 源代码控制集成。
Alternatively, there is a project called Git Extensionsthat includes add-ins for Visual Studio 2005, 2008, 2010 and 2012, as well as Windows Explorer integration. It's regularly updated and having used it on a couple of projects, I've found it very useful.
或者,有一个名为Git Extensions的项目,其中包括 Visual Studio 2005、2008、2010 和 2012 的加载项,以及 Windows 资源管理器集成。它定期更新并在几个项目中使用它,我发现它非常有用。
Another option is Git Source Control Provider.
另一种选择是Git Source Control Provider。
回答by Jon Skeet
I use Git with Visual Studio for my port of Protocol Buffers to C#. I don't use the GUI - I just keep a command line open as well as Visual Studio.
我将 Git 与 Visual Studio 一起用于我的协议缓冲区到 C# 的端口。我不使用 GUI - 我只是保持命令行和 Visual Studio 处于打开状态。
For the most part it's fine - the only problem is when you want to rename a file. Both Git and Visual Studio would rather that theywere the one to rename it. I think that renaming it in Visual Studio is the way to go though - just be careful what you do at the Git side afterwards. Although this has been a bit of a pain in the past, I've heard that it actually should be pretty seamless on the Git side, because it can notice that the contents will be mostly the same. (Not entirely the same, usually - you tend to rename a file when you're renaming the class, IME.)
在大多数情况下,这很好 - 唯一的问题是您想重命名文件时。Git 和 Visual Studio 都希望自己重命名它。我认为在 Visual Studio 中重命名它是可行的方法 - 之后在 Git 端做的事情要小心。虽然这在过去有点麻烦,但我听说它在 Git 方面实际上应该是非常无缝的,因为它可以注意到内容将大体相同。(通常不完全相同 - 在重命名类 IME 时,您倾向于重命名文件。)
But basically - yes, it works fine. I'm a Git newbie, but I can get it to do everything I need it to. Make sure you have a git ignore file for bin and obj, and *.user.
但基本上 - 是的,它工作正常。我是 Git 新手,但我可以让它做我需要做的一切。确保你有一个用于 bin 和 obj 的 git ignore 文件,以及 *.user。
回答by yysun
Git Source Control Provideris new plug-in that integrates Git with Visual Studio.
Git Source Control Provider是将 Git 与 Visual Studio 集成的新插件。
回答by T.E.D.
I've looked into this a bit at work (both with Subversion and Git). Visual Studio actually has a source control integration API to allow you to integrate third-party source control solutions into Visual Studio. However, most folks don't bother with it for a couple of reasons.
我在工作中对此进行了一些研究(使用 Subversion 和 Git)。Visual Studio 实际上有一个源代码控制集成 API,允许您将第三方源代码控制解决方案集成到 Visual Studio 中。但是,出于以下几个原因,大多数人不会为此烦恼。
The first is that the API pretty much assumes you are using a locked-checkout workflow. There are a lot of hooks in it that are either way expensive to implement, or just flat out make no sense when you are using the more modern edit-merge workflow.
首先是 API 几乎假定您使用的是锁定结账工作流程。其中有很多钩子要么实现起来很昂贵,要么在您使用更现代的编辑合并工作流程时完全没有意义。
The second (which is related) is that when you are using the edit-merge workflow that both Subversion and Git encourage, you don't really needVisual Studio integration. The main killer thing about SourceSafe's integration with Visual Studio is that you (and the editor) can tell at a glance which files you own, which must be checked out before you can edit, and which you cannot check out even if you want to. Then it can help you do whatever revision-control voodoo you need to do when you want to edit a file. None of that is even part of a typical Git workflow.
第二个(相关的)是,当您使用 Subversion 和 Git 都鼓励的编辑合并工作流时,您实际上并不需要Visual Studio 集成。SourceSafe 与 Visual Studio 集成的主要优势在于,您(和编辑器)可以一眼看出您拥有哪些文件,哪些文件必须在编辑前签出,哪些即使您愿意也无法签出。然后,它可以帮助您执行编辑文件时需要执行的任何修订控制伏都教。这些甚至都不是典型 Git 工作流程的一部分。
When you are using Git (or SVN typically), your revision-control interactions all take place either before your development session, or after it (once you have everything working and tested). At that point it really isn't too much of a pain to use a different tool. You aren't constantly having to switch back and forth.
当您使用 Git(或通常使用 SVN)时,您的修订控制交互都发生在您的开发会话之前或之后(一旦您使一切正常并经过测试)。在这一点上,使用不同的工具真的不是一件很痛苦的事情。您不必经常来回切换。
回答by CB Bailey
I find that Git, working on whole trees as it does, benefits less from IDE integration than source control tools that are either file based or follow a checkout-edit-commit pattern. Of course there are instances when it can be nice to click on a button to do some history examination, but I don't miss that very much.
我发现与基于文件或遵循 checkout-edit-commit 模式的源代码控制工具相比,Git 在处理整棵树时从 IDE 集成中获益较少。当然,在某些情况下,单击按钮进行一些历史检查会很不错,但我并不太想念它。
The real must-do is to get your .gitignore file full of the things that shouldn't be in a shared repository. Mine generally contain (amongst other stuff) the following:
真正必须做的是让您的 .gitignore 文件充满不应该在共享存储库中的内容。我的通常包含(除其他外)以下内容:
*.vcproj.*.user
*.ncb
*.aps
*.suo
but this is heavily C++ biased with little or no use of any class wizard style functionality.
但这严重偏向于 C++,很少或根本没有使用任何类向导风格的功能。
My usage pattern is something like the following.
我的使用模式类似于以下内容。
Code, code, code in Visual Studio.
When happy (sensible intermediate point to commit code, switch to Git, stage changes and review diffs. If anything's obviously wrong switch back to Visual Studio and fix, otherwise commit.
代码,代码,Visual Studio 中的代码。
高兴时(提交代码的明智中间点,切换到 Git,暂存更改并查看差异。如果有任何明显错误,请切换回 Visual Studio 并修复,否则提交。
Any merge, branch, rebase or other fancy SCM stuff is easy to do in Git from the command prompt. Visual Studio is normally fairly happy with things changing under it, although it can sometimes need to reload some projects if you've altered the project files significantly.
任何合并、分支、变基或其他花哨的 SCM 内容都可以从命令提示符在 Git 中轻松完成。Visual Studio 通常对它下发生的变化相当满意,尽管如果您对项目文件进行了重大更改,它有时可能需要重新加载某些项目。
I find that the usefulness of Git outweighs any minor inconvenience of not having full IDE integration but it is, to some extent, a matter of taste.
我发现 Git 的用处超过了没有完整 IDE 集成的任何小不便,但在某种程度上,这是一个品味问题。
回答by Chandramouleswaran Ravichandra
Microsoft announced Git for Visual studio 2012(update 2) recently. I have not played around with it yet, but this videolooks promising.
微软最近宣布了适用于 Visual Studio 2012(更新 2)的Git。我还没有玩过它,但这个视频看起来很有希望。
Here is a quick tutorialon how to use Git from Visual Studio 2012.
这是有关如何从 Visual Studio 2012 使用 Git的快速教程。
回答by tonyo
Also don't miss TortoiseGit... https://tortoisegit.org/
也不要错过 TortoiseGit ... https://tortoisegit.org/
回答by u109919
There's a Visual Studio Tools for Gitby Microsoft. It only supports Visual Studio 2012 (update 2) though.
微软有一个Visual Studio Tools for Git。不过它只支持 Visual Studio 2012(更新 2)。
回答by rhughes
Visual Studio 2013 natively supports Git.
Visual Studio 2013 本身支持 Git。
See the official announcement.
见官方公告。
回答by Philippe
The Git support done by Microsoft in Visual Studio is just good enough for basic work (commit/fetch/merge and push). My advice is just to avoid it...
Microsoft 在 Visual Studio 中完成的 Git 支持对于基本工作(提交/获取/合并和推送)来说已经足够了。我的建议只是避免它......
I highly prefer GitExtensions(or in less proportion SourceTree). Because seeing the DAGis for me really important to understand how Git works. And you are a lot more aware of what the other contributors to your project have done!
我非常喜欢GitExtensions(或比例较小的 SourceTree)。因为看到DAG对我来说对于理解 Git 的工作方式非常重要。而且你更清楚你项目的其他贡献者做了什么!
In Visual Studio, you can't quickly see the diff between files or commit, nor (add to the index) and commit only part of modifications. Browse your history is not good either... All that ending in a painful experience!
在 Visual Studio 中,您无法快速查看文件或提交之间的差异,也无法(添加到索引)并仅提交部分修改。浏览你的历史也不好......所有这一切都以痛苦的经历结束!
And, for example, GitExtensions is bundled with interesting plugins: background fetch, GitFlow,... and now, continuous integration!
而且,例如,GitExtensions 捆绑了一些有趣的插件:后台获取、GitFlow ……现在,持续集成!
For the users of Visual Studio 2015, Git is taking shape if you install the GitHub extension. But an external tool is still better ;-)
对于Visual Studio 2015的用户,如果你安装了 GitHub 扩展,Git 正在形成。但是外部工具仍然更好;-)