简体   繁体   English

为什么在SVN中使用未提交的更改切换分支?

[英]Why can you switch branch in SVN with uncommited changes?

I come from git so maybe there's something I am missing. 我来自git,所以也许我缺少一些东西。 Find an example below: 在下面找到一个例子:

Let's say I have the branch master and the branch release, I do some changes in master and I switch to release without committing the changes, in git I would get something like "Cannot switch branch with uncommitted changes, please commit or stash them". 假设我有分支master和分支release,我对master进行了一些更改,然后切换到发布而不提交更改,在git中,我会得到类似“无法使用未提交的更改切换分支,请提交或存储它们”的信息。 However in my recent experience with SVN at my new company not only I could switch the branch without problems but my changes were still there! 但是,根据我最近在新公司中使用SVN的经验,我不仅可以毫无问题地切换分支机构,而且我的更改仍然存在!

I am a little bit confused so some guidance would be appreciated. 我有些困惑,因此请多多指教。

Just checkout a new working copy with the branch you need. 只需使用您需要的分支签出新的工作副本。 With Subversion you can have unlimited number of working copies. 使用Subversion,您可以拥有无​​限数量的工作副本。

Short answer: it just is the way it is because the developers wanted it to be that way. 简短的回答:就是这样,因为开发人员希望它是那样。

As you noted, git tells you how to get the svn behaviour (by doing git stash && git checkout xyz && git stash pop ). 如您所述, git告诉您如何获得svn行为(通过执行git stash && git checkout xyz && git stash pop )。

Long answer: I assume the reason why the git developers prefered to do is this way is because keeping your changes during a checkout is ultimately a 3-way-merge operation. 长答案:我认为git开发人员更喜欢这样做的原因是因为在结帐期间保留更改最终是3向合并操作。 These can cause conflicts and are generally "heavy". 这些会引起冲突,并且通常是“沉重的”。 By enforcing a git checkout to be possible only on a clean working directory, you are guaranteed that git will either fail fast and painless, or be successful. 通过强制仅在干净的工作目录上执行git checkout ,可以确保git快速失败或成功。

It's the same when you do a merge and your working directory is not clean. 进行合并且工作目录不干净时,情况相同。 git will also deny that operation. git也将拒绝该操作。

All of this is for your protection. 所有这些都是为了保护您。 The uncommitted working directory (and index) changes are not protected by a commit. 未提交的工作目录(和索引)更改不受提交保护。 If something goes wrong, they would be gone forever, with no way to recover. 如果出现问题,它们将永远消失,无法恢复。 Failed merge conflict resolution is amongst the very, very few things that can go wrong when you work with git , and git has no possible way to avoid that (because the resolution is a human operation). 失败的合并冲突解决方案是使用git时会出错的极少数事情,而git无法避免这种情况(因为解决方案是人工操作)。

So, if git were to allow checkout or merge into an unclean working directory, it would have to do a git stash (or something similar) for you in the background; 因此,如果git允许checkoutmerge到不干净的工作目录中,则它必须在后台为您执行git stash (或类似操作); the design decision was simply to leave that to you, and to avoid weird constellations that could possibly lead to data loss. 设计决策只是将其留给您,并避免可能导致数据丢失的怪异星座。

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

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