Git + GitHub + Heroku [英] Git + GitHub + Heroku

查看:97
本文介绍了Git + GitHub + Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Git,GitHub和Heroku的新手。到目前为止,我很喜欢这个范例,但是来自SVN的背景,在Git的世界里,对我来说事情似乎有点复杂。我遇到了一个我正在寻找解决方案的问题。



场景:

1。我在GitHub上建立了一个新的私人项目。我分叉了私人项目,现在我的分支中有以下结构:

  /项目
/ apps
/ my-apps
/ my-app-1
....
/ my-app-2
....
/ your-apps
/ your-app-1
....
/ your-app-2
....
/ plugins
....

我可以在我的机器中的任意文件夹中将我的Fork中的代码提交到GitHub中。稍后,这些将由项目的管理员拉入主存储库。



2。对于应用程序文件夹中的每个应用程序,我已经在Heroku上设置了一个应用程序,这是一个Git Repo,当我完成来自本地机器的用户故事时,我推送了更改。简而言之,应用程序文件夹中的每个应用程序都是Heroku上托管的Rails应用程序。



问题:

我想要的是,当我将更改推送到Heroku中时,它们可以在GitHub中承诺到我的项目分支中,所以它也始终具有最新的代码。



我看到的问题是Heroku上的代码是Git Repo,而我在GitHub上的文件夹是Repo的一部分。



<到目前为止,我研究的是在Git World中有一些被称为Submodule的子模块,可以帮助解决,但是我一直没有找到一些新手指令。

社区中的某个人是否可以友好地分享想法并帮助我找出解决方案?

子模块背后的想法是它们都是独立的git存储库,您可以将其包含到主存储库中,而不是包含它包含的所有文件链接到该子模块。



如何使用子模块



子模块,首先必须使用 git init 来提取出目录并将其创建为其自己的git存储库。然后,你可以单独上传到Github或[你选择的地方],并使用它作为子模块使用命令: git submodule add [place / to / put / it] git:// github。 com / you / proj1



分离效果最好

我认为最好将这些分离出来的作为自己的git仓库,并从每个仓库推送到heroku。原因?更有可能(我觉得)你将一次一个工作,做一个 git commit git push heroku master 仅限那一个。



如果您希望同时部署所有应用程序,则可以使用放置在顶层目录中的这个Ruby脚本递归目录树:

  Dir [** / *]。select {| dir | File.directory?(dir)} .each do | f | 
Dir.chdir(dir)do
`git push origin master`
`git push heroku master`
end
end

当然,这只有在您已经完成所有更改后才有效。由于Ruby< = 1.9没有模块来读取您的想法,所以我想不出一种自动化的方法。

I am new to the world of Git, GitHub and Heroku. So far, I am enjoying this paradigm but coming from a background with SVN, things seems a bit complicated to me in the world of Git. I am facing a problem for which I am looking for a solution.

Scenario:

1. I have setup a new private project on GitHub. I forked the private project and now I have the following structure in my branch:

    /project
      /apps
        /my-apps
          /my-app-1
            ....
          /my-app-2
            ....
          /your-apps
            /your-app-1
              ....
            /your-app-2
              ....
      /plugins
         ....

I can commit the code in my Fork on GitHub from my machine in any of the folders I want. Later on, these would be pulled into the master repository by the admin of the project.

2. For every individual application in the apps folder, I have setup an app on Heroku which is a Git Repo in itself where I push my changes when I am done with the user stories from my local machine. In short, every app in the apps folder is a Rails App hosted on Heroku.

Problem:

What I want is that when I push my changes into Heroku, they can be committed into my project fork on GitHub as well, so, it also has the latest code all the time.

The issue I see is that the code on Heroku is a Git Repo while the folders which I have on GitHub are part of a Repo.

So far, what I have researched is that there is something known as Submodule in the Git World which can come to the rescue, however, I have not been able to find some newbie instructions.

Can someone in the community be kind enough to share thoughts and help me to identify the solution of this problem?

解决方案

The idea behind submodules is that they're all separate git repositories that you can include into a master one and rather instead of including all the files it includes a link to that submodule instead.

How to use submodules

To use a submodule, first you must extract out the directory and create it as its own git repository by using git init. Then you can upload this separately to Github or [place of your choosing] and to use it as a submodule use the command: git submodule add [place/to/put/it] git://github.com/you/proj1.

Separation is best

I would think it better to leave these separated out as their own git repositories and push to heroku from each one. The reason? It's more likely (I feel) that you're going to be working on one at a time and doing a git commit and git push heroku master for that one only.

If you wished however to deploy all applications at the same time you could recurse down the directory tree using this Ruby script placed in the top-level directory:

Dir["**/*"].select { |dir| File.directory?(dir) }.each do |f|
  Dir.chdir(dir) do
    `git push origin master`
    `git push heroku master`
  end
end

Of course this would only work if you have staged all your changes. I can't think of a way to automate that as Ruby <= 1.9 doesn't have the module to read your thoughts.

这篇关于Git + GitHub + Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆