jjzjj

git - 组织 git 分支

coder 2023-06-24 原文

我有一个大型项目,我正在使用 git 作为 VCS。在任何给定时间,我都在努力实现一些功能/错误修复等。对于任何给定的功能/错误,创建分支层次结构会很好——例如

$ git branch
  feature1
       sub-branch1
       sub-branch2
       sub-branch3
  feature2
       sub-brancha
      *sub-branchb  #<--currently checked out
       sub-branchc
  bugfix1
       sub-branch-foo

$ git checkout sub-brancha
$ git branch
  feature1
       sub-branch1
       sub-branch2
       sub-branch3
  feature2
      *sub-brancha  #<--currently checked out
       sub-branchb  
       sub-branchc
  bugfix1
       sub-branch-foo

是否可以这样做,还是我需要采用更原始的命名方案?

编辑

为了使我正在寻找的内容更具体一些,如果 feature1 是一个 git 分支,那么在上面的示例中,子分支 1 将全部由 git checkout -b sub-branch1 创建。来自 feature1分支(从 master 分支出来)。例如:

$ git checkout master
$ git checkout -b feature1
$ git checkout -b testing
$ git branch
master
   feature1
     *testing
$ git checkout master
$ git checkout -b feature2
$ git branch
master
   feature1
      testing
  *feature2

让 git branch 简单地根据分支的来源组织分支(有一点额外的缩进)可能对我的目的来说已经足够了......尽管如果我可以的话 super 加分:

$ git branch
  feature1
       testing
  feature2
       testing
  bugfix1
       sub-branch-foo

通过某种方式来管理“feature1/testing”和“feature2/testing”之间的名称冲突

最佳答案

您可以使用像 feature1/sub-brancha、feature2/sub-branchb 等命名模式,名称中的斜杠对 git 来说不是问题。但是,分支仍将作为普通分支处理(但我不知道如何以不同方式处理子分支)。 git branch 命令当然会列出分支及其全名,而不是示例中的方式。

有趣的是,包含斜杠的命名模式将在 .git/refs/heads/中创建一个目录层次结构。也许这对于使用一些低级命令处理子分支很有用?

关于git - 组织 git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051289/

有关git - 组织 git 分支的更多相关文章

  1. git使用常见问题(提交代码,合并冲突) - 2

    文章目录git常用命令(简介,详细参数往下看)Git提交代码步骤gitpullgitstatusgitaddgitcommitgitpushgit代码冲突合并问题方法一:放弃本地代码方法二:合并代码常用命令以及详细参数gitadd将文件添加到仓库:gitdiff比较文件异同gitlog查看历史记录gitreset代码回滚版本库相关操作远程仓库相关操作分支相关操作创建分支查看分支:gitbranch合并分支:gitmerge删除分支:gitbranch-ddev查看分支合并图:gitlog–graph–pretty=oneline–abbrev-commit撤消某次提交git用户名密码相关配置g

  2. ruby - Dropbox 类似 git 的服务——没有 rsync 和 inotify - 2

    关于如何使用git设置类似Dropbox的服务,您有什么建议吗?您认为git是解决此问题的合适工具吗?我在考虑使用git+rush解决方案,你觉得怎么样? 最佳答案 检查这个开源项目:https://github.com/hbons/SparkleShare来自项目的自述文件:Howdoesitwork?SparkleSharecreatesaspecialfolderonyourcomputer.Youcanaddremotelyhostedfolders(or"projects")tothisfolder.Theseprojec

  3. ruby - 混帐 & ruby : How can I unset the GIT_DIR variable from inside a ruby script? - 2

    我编写了一个非常简单的“部署”脚本,作为我的裸git存储库中的post-updateHook运行。变量如下livedomain=~/mydomain.comstagingdomain=~/stage.mydomain.comgitrepolocation=~/git.mydomain.com/thisrepo.git(bare)core=~/git.mydomain.com/thisrepo.gitcore==addedremoteintoeachlive&stagegitslive和stage都初始化了gitrepos(非裸),我已经将我的裸仓库作为远程添加到它们中的每一个(名为co

  4. ruby - 让 bundler 使用 http : instead of git:? - 2

    我正在安装gitlabhq,并且在Gemfile中有对某些资源的“git://...”的引用。但是,我在公司防火墙后面,所以我必须使用http://。我可以手动编辑Gemfile,但我想知道是否有另一种方法告诉bundler使用http://作为git存储库? 最佳答案 您可以通过运行gitconfig--globalurl."https://".insteadOfgit://或通过将以下内容添加到~/.gitconfig:[url"https://"]insteadOf=git://

  5. ruby-on-rails - 安装 active admin 时 activeadmin.git (at master) is not yet checked out 错误 - 2

    Activeadmingem已添加到我的rails项目中,但每次我尝试安装railsgactive_admin:install时,我都会收到类似的错误git://github.com/activeadmin/activeadmin.git(atmaster)isnotyetcheckedout.Runbundleinstallfirst.我肯定在运行“railsgactive_admin:install”之前运行了bundle。运行“bundleshow”后,我看到我已将“*activeadmin(1.0.0.pre3f916d6)”添加到我的项目中,但不断收到此错误消息。我的gem文

  6. ruby - 如何让 GitHub 页面使用 master 分支? - 2

    我有一个使用Jekyll托管在GitHub上的静态网站。问题是,我真的不需要master分支,因为存储库唯一包含的是网站。这样我就必须gitcheckoutgh-pages,然后gitmergemaster,然后gitpushorigingh-pages。有什么简单的方法可以摆脱gh-pages分支并直接从master推送? 最佳答案 Theproblemis,Idon'treallyneedthemasterbranch,astheonlythingtherepositorycontainsisthewebsite.Isthere

  7. ruby - 分配分支条件太高 - 2

    我有一个简单的类,它在初始化时接受一到八个参数。它将访问器设置为这些访问器以供以后使用。Rubocop正试图以ABC太高为由逮捕我,但我不确定我所做的是否真的有任何问题。在这种情况下,我只是在初始化时禁用检查吗?classFooattr_accessor:one,:two,:three,:fourattr_accessor:five,:six,:seven,:eightdefinitialize(p={})@one=p[:one]ifp[:one].present?#...@eight=p[:eight]ifp[:eight].present?endend关于减小大小,我唯一的想法是做

  8. ruby-on-rails - 在 Rails 4 中组织外部 API 调用 - 模块还是类? - 2

    我正在创建一个Rails应用程序,它将使用相当多的外部API,例如SalesForce、FolderGrid(如Dropbox)等,它们都会同步到我的数据库。我从来没有使用过外部api调用,所以我创建了一些基本的Ruby脚本和分散的方法来测试对这些资源的调用。现在我想用我的完整Rails应用程序来实现它们。到目前为止,我首先在我的/lib文件夹中创建一个目录来保存api调用模块/类。/lib/apis/foldergrid.rb现在我不确定组织代码的最佳方法是什么。在我的独立Ruby脚本中,我有用于身份验证、创建文件夹、审核文件、下载文件等的方法。模块中应该包含什么?我什至需要一个模块

  9. ruby - git:从 bitbucket 导出并导入 github(带提交) - 2

    我在bitbucket上创建了一个私有(private)git存储库并提交了代码。现在我想导出所有(提交、代码、历史记录)并将其导入github上的gitrepo。有没有办法做到这一点?谢谢 最佳答案 在本地检查所有内容到您的计算机和gitpull。创建一个github存储库将此存储库添加为您的第二个远程(“使用gitremote添加githubURL”)推送到第二个Remote 关于ruby-git:从bitbucket导出并导入github(带提交),我们在StackOverflow

  10. Unity 报错No ‘git‘ executable was found. Please install Git on your system then restart - 2

    亲测可用。Anerroroccurredwhileresolvingpackages:Projecthasinvaliddependencies: com.unity.xxx:No'git'executablewasfound.PleaseinstallGitonyour  systemthenrestartUnityandUnityHub在我们使用PackageManager时,Unity允许我们使用Git上的package(点击加号,选择addpackagefromgitURL,或者是直接在Asset/Packages/manifest.json中添加包名)。但是这种操作需要我们事先装好g

随机推荐