如何将我的 git repo 的一部分推送到 Heroku?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5977234/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:27:48  来源:igfitidea点击:

How can I push a part of my git repo to Heroku?

githeroku

提问by Behrang Saeedzadeh

I have a multi-module app that is already on Github. It is comprised of two modules, one of them an Android app and the other a Rails based Web app. So my project's directory structure is in the form of:

我有一个已经在 Github 上的多模块应用程序。它由两个模块组成,一个是 Android 应用程序,另一个是基于 Rails 的 Web 应用程序。所以我的项目的目录结构是这样的形式:

ProjectRoot
|
+-- web
|
+-- android
|
+-- .git

As such I cannot simply cdinto ProjectRoot and push my app to Heroku as the root folder of the Rails app is ProjectRoot/web. Is there a way to push the webfolder to Heroku? If I turn web into a git sub module, it should be easy to accomplish this, but then I only have 5 private repos on Git and I prefer to consume only 1 repo for my whole app.

因此,我不能简单地cd进入 ProjectRoot 并将我的应用程序推送到 Heroku,因为 Rails 应用程序的根文件夹是ProjectRoot/web. 有没有办法将web文件夹推送到 Heroku?如果我将 web 变成一个 git 子模块,应该很容易实现这一点,但是我在 Git 上只有 5 个私有存储库,而且我更愿意为我的整个应用程序只使用 1 个存储库。

回答by Micha?l Witrant

You can use git subtree push. It will generate a new commit tree with your directory as root, and push it.

您可以使用git subtree push. 它将生成一个以您的目录为根目录的新提交树,并推送它。

git subtree push --prefix web heroku master

Full documentation is here.

完整文档在这里

回答by brookr

The git subtreecommand (built in, now) is a good way to do this. If you want to push a subtree of a branch to become your master, you can use something like:

git subtree命令(在建,现在)是一个很好的办法做到这一点。如果你想推动一个分支的子树成为你的主人,你可以使用类似的东西:

git push --force heroku `git subtree split --prefix web HEAD`:master

git push --force heroku `git subtree split --prefix web HEAD`:master

回答by bmaland

You could also use git branches instead of subfolders. If you have git 1.7.2 or newer, you can simply do git checkout --orphan androidto create a branch that is disconnected from your master branch (assumed here to be the web folder). Once you have checked out the orphan branch, run git rm -rf .to remove existing files before copying in your android-specific files to the now empty root directory.

您还可以使用 git 分支而不是子文件夹。如果您有 git 1.7.2 或更新版本,您可以简单git checkout --orphan android地创建一个与主分支断开连接的分支(这里假设为 web 文件夹)。检出孤立分支后,运行git rm -rf .以删除现有文件,然后再将您的 android 特定文件复制到现在为空的根目录。

If you want to use separate folders for each module, you can clone the repository twice and use this structure:

如果您想为每个模块使用单独的文件夹,您可以克隆存储库两次并使用以下结构:

ProjectRoot
├── android
│?? └── .git
└── web
    └── .git