git - 分支别名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14365946/
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
git - branch alias?
提问by user606723
I am researching switching from starteam to git.
我正在研究从 Starteam 切换到 git。
Currently, in starteam, we use "floating views" with special names. These floating views basically work like aliases. Therefore, we can specify a specific alias to checkout from and we'll get the branch that we're currently model testing.
目前,在星际团队中,我们使用带有特殊名称的“浮动视图”。这些浮动视图基本上像别名一样工作。因此,我们可以指定一个特定的别名来结帐,我们将获得我们当前正在模型测试的分支。
How would this be done in git? This is basically how our branches are organized:
这将如何在 git 中完成?我们的分支机构基本上是这样组织的:
These are all branches
这些都是分支
master (stable view)
| - Branch 2012.05.01
| | - Project 1
| | - Project 2
| | - model [floating view / alias to Branch 2012.05.01]
|
| - Branch 2012.07.11 (these would also have various child views for projects)
| - Branch 2012.10.17
(Branch 2012.05.01 would be merged to master when model testing is complete)
(当模型测试完成后,分支 2012.05.01 将合并到 master)
In our automated scripts(ant) to run our model deployment, we just checkout from our branch called "model". This way we never have to change our scripts as we change which Branch we are model testing, and finding out which view we're model testing is as easy as figuring out which branch the "model" branch references.
在我们运行模型部署的自动化脚本(ant)中,我们只需从名为“模型”的分支中检出。这样我们就不必在更改模型测试的分支时更改脚本,并且找出我们正在模型测试的视图就像找出“模型”分支引用哪个分支一样简单。
Is there any such way to do something similar in git?
有没有这样的方法可以在 git 中做类似的事情?
Edit: people are getting confused here.
编辑:人们在这里感到困惑。
- I want an alias of a branch. A branch, not a commit.
- "Branch 2012.05.01" means the branch intended to be shipped on 2012.05.01, it doesn't mean a 2012.05.01 moment in time
- I want a alias to Branch 2012.05.01. Branch 2012.05.01 is an integration branch, it's constantly modified. But I don't want to reference it as Branch 2012.05.01, I want to reference it as "model". This way, I can change my the alias to "Branch 2012.07.11" and it will get the most recent code from that branch without changing any of the checkout code script.
- 我想要一个分支的别名。一个分支,而不是一个提交。
- “Branch 2012.05.01”是指打算在 2012.05.01 发布的分支,不代表 2012.05.01 时刻
- 我想要一个分支 2012.05.01 的别名。分支 2012.05.01 是一个集成分支,它在不断地修改。但我不想将其引用为 Branch 2012.05.01,我想将其引用为“模型”。这样,我可以将别名更改为“Branch 2012.07.11”,它将从该分支获取最新代码,而无需更改任何结帐代码脚本。
回答by user606723
Please see here: https://stackoverflow.com/a/549949/606723
请看这里:https: //stackoverflow.com/a/549949/606723
You can rename the master branch trunk as Greg has suggested, or you can also create a trunk that is a symbolic reference to the master branch so that both git and svn users have the 'main' branch that they are used to.
git symbolic-ref refs/heads/trunk refs/heads/master
Note that trunk isn't a first class citizen. If you checkout trunk and perform a git status you will actually be on master, however you can use the trunk command in all places that you use the branch name (log, merge, etc.).
您可以按照 Greg 的建议重命名 master 分支主干,或者您也可以创建一个作为主分支的符号引用的主干,以便 git 和 svn 用户都拥有他们习惯的“主”分支。
git symbolic-ref refs/heads/trunk refs/heads/master
请注意,trunk 不是一等公民。如果您检出主干并执行 git status 您实际上将在 master 上,但是您可以在所有使用分支名称的地方(日志、合并等)使用 trunk 命令。
回答by Adam Dymitruk
Git does not support aliases for branches.
Git 不支持分支的别名。
This means you will have to rely on variables in your script to make model="branch.2012.10.17" or something like that. Your script would do something like this then:
这意味着您将不得不依赖脚本中的变量来制作 model="branch.2012.10.17" 或类似的东西。然后你的脚本会做这样的事情:
git checkout $model
I'm leaving the rest of this answer here for where we came from in this discussion:
我将这个答案的其余部分留在这里,以了解我们在本次讨论中的来源:
A very involved discussion on branching strategy can be found here: http://dymitruk.com/blog/2012/02/05/branch-per-feature/
可以在此处找到有关分支策略的非常复杂的讨论:http: //dymitruk.com/blog/2012/02/05/branch-per-feature/
Specifically, take a look at the role of the integration branch and the release candidate branch. This may be what you are looking for.
具体看一下集成分支和发布候选分支的作用。这可能就是您正在寻找的。
Look at git as something that takes a snapshot of your working directory, not as histories of folders.
将 git 视为获取工作目录快照的东西,而不是文件夹的历史记录。
progit.org/book explains the Directed Acyclic Graph that stores the history. All references are just things that point to nodes in it. That should clarify how you want to construct your workflow.
progit.org/book 解释了存储历史的有向无环图。所有引用都只是指向其中的节点的东西。这应该阐明您想要如何构建您的工作流程。
make a start tag - version2.1. from there make your int-version2.1 (using nubmers instead of dates for brevity). Any work you start, start from the version 2.1 tag. merge the work into the int-version2.1. Others will do the same.
制作一个开始标签 - version2.1。从那里制作您的 int-version2.1(为简洁起见,使用数字代替日期)。你开始的任何工作,都是从 2.1 版标签开始的。将工作合并到 int-version2.1 中。其他人也会这样做。
回答by iMysak
In case when you need branch per feature — answer of Adam Dymitruk is correct, But in case when you need save links branch - specific state (based on time), without changed them you can use git tags.
如果您需要每个功能的分支 - Adam Dymitruk 的答案是正确的,但是如果您需要保存链接分支 - 特定状态(基于时间),无需更改它们,您可以使用 git 标签。
I used tags for store states of each prod releases.
我使用标签来表示每个产品版本的存储状态。