15

我正在尝试在 Heroku 上创建一个暂存分支,但有些东西我不太明白。

假设我已经创建了一个 heroku 应用程序并将遥控器设置为指向 staging-remote,如果我这样做:

git checkout -b staging staging-remote/master

我有一个名为“staging”的本地分支,它跟踪 staging-remote/master - 或者这就是我的想法......

但:

git remote show staging-remote

给我这个:

remote staging
  Fetch URL: git@heroku.com:myappname.git
  Push  URL: git@heroku.com:myappname.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    staging-remote merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

如您所见,pull 看起来很合理,但默认 push 不合理。这意味着如果我这样做:

git push 暂存远程

我将把我的本地主分支推送到暂存分支。但这不是我想要的......基本上,我想将更新合并到我的暂存分支中,然后轻松将其推送到 heroku,而无需像这样指定分支:

git push staging-remote mybranch:master

以上并不难做到,但我想避免意外地进行先前的推送并推送错误的分支......这对于我想要创建的生产分支来说是双重重要的!

我试过弄乱 git config,但还没有弄清楚如何做到这一点......

4

7 回答 7

25

我已经对其进行了测试,@juba 和@MatthewFord 的版本完美运行!

git config remote.staging.push staging:master

这会将名为staging的本地主题分支推送到名为staging的远程存储库上的远程分支master中。

@nickgrim 把它放在一般形式中,如下所示:

git config remote.[remoteRepositoryName].push [localBranchName]:[remoteBranchName]

更新:

git push此外,当您使用以下-u选项时,现代 git 将方便地为您运行上述配置命令:

git push -u staging staging:master
于 2010-10-02T09:08:07.947 回答
7

我有一个名为 heroku 的分支,这对我有用:

git config remote.heroku.push heroku:master

您面临的问题是heroku 忽略了除master 之外的所有分支。

于 2010-05-19T16:45:16.420 回答
3

From the book "O’Reilly - Version Control with Git" page 184 | Chapter 11: Remote Repositories

During a git push operation, you typically want to provide and publish the changes you made on your local topic branches. To allow others to find your changes in the remote repository after you upload them, your changes must appear in that repository as topic branches. Thus, during a typical git push command, the source branches from your repository are sent to the remote repository using a refspec such as:

+refs/heads/*:refs/heads/*

This refspec can be paraphrased as: From the local repository, take each branch name found under the source namespace refs/heads/ and place it in a similarly named, matching branch under the destination namespace refs/heads/ in the remote repository. The first refs/heads/ refers to your local repository (because you’re executing a push), and the second refers to the remote repository. The asterisks ensure that all branches are replicated. ...


That’s why the example from juba should fail. the corrected refspec should be:

git config remote.staging-remote.push +refs/heads/local_branch_name:refs/heads/master
于 2010-06-17T15:05:39.933 回答
1

带有 20 个左右命令的 Everiday Git页面:

http://www.kernel.org/pub/software/scm/git/docs/everyday.html

您似乎可以通过向本地 git 存储库添加配置指令来实现您想要做的事情,例如:

git config remote.staging-remote.push mybranch:refs/remotes/staging-remote/master

然后,如果您git pushmybranch本地分支执行操作,则应将其推送到staging-remote远程的分支。

尽管如此,请git remote show staging-remote在使用之前验证并仔细测试它,因为我远非 git 专家......

于 2010-04-07T09:57:20.203 回答
0

这行得通。我已经多次使用它来设置带有 git-flow、heroku 和备份 git 服务的客户端。

.git/config 用于回购:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
[heroku]
  account = youraccount
[remote "origin"]
  url = git@bitbucket.org:youruser/yoursite.heroku.com.git # or github, etc.
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
[branch "staging"]
  remote = origin
  merge = refs/heads/staging
[branch "develop"]
  remote = origin
  merge = refs/heads/develop
[remote "production"]
  pushurl = git@heroku.com:your-prod-app.git
  push = master:master
[remote "staging"]
  pushurl = git@heroku.com:your-staging-app.git
  push = staging:master

一切正常:

git push origin

git pull origin

git push staging

git push production

将 fetch 和 push 视为像 stdout 和 stdin 一样,两者都可以重定向或关闭为一种方式。此外,如果有人知道如何在不破解 .git/config 的情况下获得这些设置,请随时进行修改,业力点肯定会随之而来。

于 2012-04-24T02:51:08.543 回答
0

我想不出办法做到这一点,但最后我找到了一个方便的 rake 任务来让它变得简单: http ://www.jbarnette.com/2009/11/10/deploying-to-heroku.html

于 2010-03-09T10:20:01.433 回答
0

我在试图弄清楚如何处理 Heroku 忽略除“master”之外的所有分支的政策时遇到了同样的问题。如果您只能在 Heroku 上测试主分支,那么它就有点破坏了保持单独分支的全部意义。

这种限制的结果是,无论我在处理什么本地主题分支,我都想要一种简单的方法将 Heroku 的主分支切换到该本地主题分支并执行“git push -f”来覆盖 Heroku 上的主分支。不用说,拥有一个单独的远程存储库(如 Github)是一个非常好的主意,可以不受此限制地备份所有内容。我会称其为“起源”并为 Heroku 使用“heroku”,以便“git push”始终备份所有内容。

我从阅读http://progit.org/book/ch9-5.html的“Pushing Refspecs”部分得到的是

git push heroku local-topic-branch:refs/heads/master

我真正想要的是一种在配置文件中进行设置的方法,以便“git push heroku”始终执行上述操作,将“local-topic-branch”替换为我当前分支的名称。

我可能会问这个作为一个新问题,看看是否有其他人知道如何做到这一点。

于 2010-06-04T02:47:33.883 回答