简体   繁体   English

Git与Visual Studio 2013

[英]Git with Visual Studio 2013

Although I have been developing with Visual Studio for years I've never had a need to get to grips with version control until recently so please excuse my ignorance if it appears I'm being stupid. 尽管我使用Visual Studio进行开发已有多年,但直到最近我才需要掌握版本控制,因此,如果我看起来很愚蠢,请原谅我的无知。

I have committed a website project to the master branch of my repository. 我已经将一个网站项目提交到了存储库的master分支。 I have created a branch underneath the master called "stage2". 我在母版下创建了一个分支“ stage2”。 The intention is that the master would be used to maintain the existing live site and "stage2" would be used for developments for the next release but don't want to be included in any published builds until the development is complete. 目的是使用母版来维护现有的实时站点,而将“ stage2”用于下一个发行版的开发,但是在开发完成之前,不希望将其包含在任何已发布的版本中。 However I can't switch back to master from "stage2" while there are uncommitted changes. 但是,在未提交更改的情况下,我无法从“ stage2”切换回主服务器。 I think I might misunderstanding exactly how the git branches are supposed to be used. 我想我可能会误解git分支应该如何使用。 Can anyone clear this up for me? 谁能为我解决这个问题?

Thanks 谢谢

It sounds like you've got the basic idea of branches right, but that you are unfamiliar with commits. 听起来您已经正确了解了分支的基本概念,但是您不熟悉提交。 I suggest you read something like this introduction to git to try to get a basic understanding of how it works. 我建议您阅读类似git入门的内容,以便对它的工作原理有一个基本的了解。

To answer your specific problem, you will need a clean working tree before you can checkout another branch. 要解决您的特定问题,您将需要一个干净的工作树,然后才能签出另一个分支。 This basically means that you need to tell git what to do with your 'in progress' work before doing anything else. 这基本上意味着您需要在执行其他任何操作之前告诉git如何处理正在进行的工作。 Assuming you don't want to throw away your changes, you could create a commit (or multiple commits) for your changes, or stash them for later. 假设你不想扔掉你的变化,你可以创建一个提交 (或多次提交)为您的更改,或藏匿他们以后。 If the changes you have made are completed 'pieces' of work, and not just temporary bits of work in progress, then I suggest you make commits for each bit of work you've done. 如果所做的更改是完成的“工作”,而不仅仅是正在进行的临时工作,那么我建议您对已完成的每一工作进行提交。

It is true that Git will not permit you to switch branches while you have uncommitted changes. 的确,当您未提交更改时,Git不允许您切换分支。

It appears you have a few choices here: 看来您有一些选择:

  1. Abandon the changes in your current branch with git reset --hard 使用git reset --hard放弃当前分支中的更改
  2. Store away the current state, temporarily, with git stash . 使用git stash暂时git stash当前状态。 When you return to the Feature Branch you can use git stash pop to restore your work 返回功能分支时,可以使用git stash pop恢复工作
  3. Make a commit of your current work on this branch and then switch branches 在此分支上提交您当前的工作,然后切换分支

You have the concept correct; 您有正确的概念; a Feature Branch is used to "do some work" with [usually] several commits along the way. 功能分支用于在执行过程中[通常]多次提交“完成某些工作”。 Commits are cheap and easy and you can always use Rebase to squash a noisy history down if you prefer. 提交既便宜又容易,并且您可以随时使用Rebase压缩嘈杂的历史记录。 Branches are lightweight and cheap so you are encouraged to use them. 分支轻巧且便宜,因此建议您使用它们。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM