使用 Git 分支

发布于 2024-10-19 02:18:35 字数 293 浏览 3 评论 0原文

我在 Heroku 上部署了一个 Rails 应用程序,并且有一个 git 存储库,目前正在处理未提交的代码更改。与此同时,我需要独立于本地存储库对 Heroku 上的源进行更改。我可以执行以下操作:

  1. 在同一开发计算机上使用不同的应用程序名称克隆 Heroku git 存储库,但使用相同的帐户
  2. 对新的本地存储库进行更改
  3. 将这些更改提交到新的本地存储库
  4. 将这些更改推送到 Heroku 存储库
  5. 恢复工作在我原来的本地存储库上

这种方法有效吗?

I have a Rails app deployed on Heroku and I have a git repo that I'm currently working on with uncommitted code changes. In the meantime, I need to make changes to the source on Heroku independently of the local repo. Can I do the following:

  1. Clone the Heroku git repo on the same development machine with a different app name though with the same account
  2. Make changes to the new local repo
  3. Commit those changes to the new local repo
  4. Push those changes to the Heroku repo
  5. Resume working on my original local repo

Will this approach work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

高速公鹿 2024-10-26 02:18:35

是的,该工作流程可以工作,或者隐藏它们 - 并且不要忘记,如果您确实克隆了 heroku 存储库,您将对该存储库的另一个克隆进行更改,并且您需要在您的原始本地仓库。

将来我建议您假设您的“主”分支是 Heroku 上的实时分支以及要在其中工作的分支 - 您甚至可以将此分支推送到新应用程序中以进行测试。这样,可以在本地 master 分支(或另一个分支并合并到 master 中)上执行错误修复并推送到 heroku,然后当您完成新工作时,将分支合并回 master 并将其部署到您的实时环境。我不久前写了一篇关于这个主题的博客文章,这里

Yep, that workflow would work, or stash them - and don't forget if you do make a clone of the heroku repo you'll have made changes to a different clone of the repo and you'll need to make those changes in your original local repo.

In future I'd suggest that you assume that your 'master' branch is what's live on Heroku and branch of that to work in - you can even push this branch into a new app for testing purposes. This way bug fixes can be performed on your local master branch (or another branch and merged into master) and pushed to heroku and then when you've finished your new work you merge the branch back into master and deploy that to your live environment. I wrote a blog article on the subject a while back, here

折戟 2024-10-26 02:18:35

我没有使用过 heroku,但如果我想在沙箱中有未保存的更改时对已部署的应用程序进行更改,我会执行以下操作之一。

  • 存储我的本地更改,从我想要进行修复的位置剪切一个分支,制作它,部署它,切换回我的原始分支并从存储中弹出。

  • 提交我未保存的更改(到当前分支 - 比如说工作),从我想要修复的位置剪切一个分支,进行修复,部署它,切换回work,将我的 HEAD 重置为“临时”提交之前并恢复工作。

除非您以非常规方式使用 git,否则无需进行另一个克隆。

I haven't used heroku but if I wanted to make changes to a deployed application while I had unsaved changes in my sandbox, I would do one of the following.

  • stash my local changes, cut a branch from the point where I want to make a fix, make it, deploy it, switch back to my original branch and pop from the stash.

  • Commit my unsaved changes (into the current branch - say work), cut a branch from the point where I want to make a fix, make my fix, deploy it, switch back to work, reset my HEAD to before my "temporary" commit and resume work.

Unless you're using git in an unconventional fashion, there's no need to make another clone.

夜司空 2024-10-26 02:18:35

如果您将 heroku 存储库克隆到一个单独的目录,进行更改并从那里推送它,那么以后可能会出现冲突。

如果这只是未提交更改的问题,那么您当然可以使用“git stash”隐藏它们,然后使用“git stash pop”检索它。

If you clone the heroku repository to a separate directory, made changes and push it from there, then there is a possibility of conflicts later down the road.

If its only the issue with the uncommitted changes then certainly you can stash them using "git stash" and later retrieve it using "git stash pop".

冷︶言冷语的世界 2024-10-26 02:18:35

我的工作周期:我总是保留一个 master 分支,其第一条规则是“在向 master 提交某些内容后始终推送到 Heroku”。如果我编写的代码不想立即部署,我就必须进行分支。

我知道这并不适用于所有用例,但始终拥有一个与 Heroku 上高效的应用程序相同的分支让我睡得更好;)

My work-cycle: I always keep a master branch with the #1 rule "always push to Heroku after committing something to master". If I code on something that I do not want to deploy immediately, I have to branch.

I know this works not for all use cases, but having always a branch that is identical to the app that is productive on Heroku makes me sleep better ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文