如何将主干/分支概念从 Subversion 转换为 Git?
所以我并不是一个源代码控制专家,我过去曾在项目中使用过 Subversion。我必须将 Git 用于特定项目(客户端提供的 Git 存储库)。
我的工作流程是这样的,我将处理来自两台不同计算机的文件,并且经常需要签入当我从一个地方移动到另一个地方时不稳定的更改,以便我可以继续我的工作。然后发生的情况是,当客户端获取最新版本时,他们也会下载不稳定的代码。
在 SVN 中,您可以通过创建主干并使用工作分支来解决此问题,或者使用主干作为工作版本并创建稳定分支。
Git 中的等效概念是什么?有没有一种简单的方法可以通过 GitHub 实现此目的?
So I am not much of a source control expert, I've used Subversion for projects in the past. I have to use Git for a particular project (client supplied Git repo).
My workflow is as such that I will be working on the files from two different computers, and often I need to check in changes that are unstable when I move from place to place so I can continue my work. What then occurs is when, say, the client goes to get the latest version, they will also download the unstable code.
In SVN, you can address this by creating a trunk and use working branches, or use the trunk as the working version and create stable branches.
What is the equivalent concept in Git, and is there a simple way to do this via GitHub?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多不同的方法可以做到这一点。如果您必须从一台计算机移动到另一台计算机,您将切换到不同的存储库,这意味着您会将更改推送到远程存储库。这很好,但这也意味着你
一个非常简单的例子就是只在私有分支上执行不稳定的工作,并给它命名一些明显的名称,例如
unstable-development
。以下是如何从头开始执行此操作。首先,让我们从客户的站点创建一个新的存储库,我将其称为“秘密酱料”。您仍然位于默认的
master
分支上。让我们创建一个新分支,以便您可以在那里而不是在master
上提交内容。好的。现在让我们添加一些不稳定的代码:
现在,
不稳定
仅存在于您这边。请注意,当我们克隆时,我们得到了一个名为origin
的远程存储库,它有一个相应的master
分支。当您的本地存储库知道远程存储库的分支时,我们将其称为“跟踪分支”。您可以使用 gitbranch -r 来查看所有远程跟踪分支:好的。让我们推迟我们的更改!
就是这样 - 我们的更改现在位于远程存储库上的
unstable
分支中。如果我们想再次查看人们在master
分支上做什么,我们可以使用git checkout master
再次切换回来。There are a lot of different ways to do this. If you have to move from computer to computer, you'll be switching to a different repository, so that means you'd be pushing up your changes to the remote repo. That's fine, but it also means you
A very simple example is to only perform your unstable work on a private branch, and to name it something obvious, e.g.
unstable-development
. Here's how to do this from scratch. First, let's make a new repo from your client's site, which I'll call "secret-sauce".You're still on the
master
branch, the default. Let's make a new branch so that you can commit stuff there instead of onmaster
.Okay. Now let's add some unstable code:
Right now,
unstable
exists only on your side. Notice that when we cloned, we got a remote repository calledorigin
, which has a correspondingmaster
branch. When your local repository knows about a remote repository's branches, we call that a "tracking branch". You can see all your remote tracking branches withgit branch -r
:Okay. Let's push our changes back!
That's it -- our changes now live in the
unstable
branch on the remote repo. If we want to see what people are up to on themaster
branch again, we can switch back again withgit checkout master
.我发现这是一个宝贵的资源:A Success Git Branching Model
与 SVN 不同,git 是去中心化的。您不需要将不稳定的代码推送到客户端的存储库。您只需将不稳定的代码从第一台计算机拉到第二台计算机即可。
话虽如此,git 可以很好地处理分支,并且应该成为您最终使用的任何方法中不可或缺的一部分。
I find this a valuable resource: A Successful Git Branching Model
Unlike SVN, git is decentralized. You shouldn't ever need to push unstable code to your client's repository. You can simply pull the unstable code to your 2nd computer from the 1st.
Having said that, git handles branching great and should be an integral part of whatever methodology you end up using.