如何将主干/分支概念从 Subversion 转换为 Git?

发布于 2024-09-01 18:37:42 字数 304 浏览 3 评论 0原文

所以我并不是一个源代码控制专家,我过去曾在项目中使用过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻拂→两袖风尘 2024-09-08 18:37:42

有很多不同的方法可以做到这一点。如果您必须从一台计算机移动到另一台计算机,您将切换到不同的存储库,这意味着您会将更改推送到远程存储库。这很好,但这也意味着你

一个非常简单的例子就是只在私有分支上执行不稳定的工作,并给它命名一些明显的名称,例如unstable-development。以下是如何从头开始执行此操作。首先,让我们从客户的站点创建一个新的存储库,我将其称为“秘密酱料”。

$ git clone git://example.com/repositories/secret-sauce.git

您仍然位于默认的 master 分支上。让我们创建一个新分支,以便您可以在那里而不是在 master 上提交内容。

$ git branch unstable
$ git checkout unstable
Switched to branch 'unstable'

好的。现在让我们添加一些不稳定的代码:

$ touch kablammo.txt
$ git add *
$ git commit -m "Added unstable code."
[master (root-commit) 9428aef] Initial checkin.
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 kablammo.txt

现在,不稳定仅存在于您这边。请注意,当我们克隆时,我们得到了一个名为 origin 的远程存储库,它有一个相应的 master 分支。当您的本地存储库知道远程存储库的分支时,我们将其称为“跟踪分支”。您可以使用 gitbranch -r 来查看所有远程跟踪分支:

$ git branch -r
  origin/HEAD -> origin/master
  origin/master

好的。让我们推迟我们的更改!

$ git push origin unstable

就是这样 - 我们的更改现在位于远程存储库上的 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".

$ git clone git://example.com/repositories/secret-sauce.git

You're still on the master branch, the default. Let's make a new branch so that you can commit stuff there instead of on master.

$ git branch unstable
$ git checkout unstable
Switched to branch 'unstable'

Okay. Now let's add some unstable code:

$ touch kablammo.txt
$ git add *
$ git commit -m "Added unstable code."
[master (root-commit) 9428aef] Initial checkin.
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 kablammo.txt

Right now, unstable exists only on your side. Notice that when we cloned, we got a remote repository called origin, which has a corresponding master 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 with git branch -r:

$ git branch -r
  origin/HEAD -> origin/master
  origin/master

Okay. Let's push our changes back!

$ git push origin unstable

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 the master branch again, we can switch back again with git checkout master.

赠意 2024-09-08 18:37:42

我发现这是一个宝贵的资源: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文