【问题标题】:Roll back git repository with deployment hook使用部署挂钩回滚 git 存储库
【发布时间】:2014-02-14 03:34:56
【问题描述】:

我在生产服务器上设置了一个裸 git 存储库,它使用 post receive hook 来部署我在那里推送的任何内容:

#!/bin/sh
GIT_WORK_TREE=/path/to/webroot git checkout -f

部署我做

git push production

从我的工作站开始,一切都得到了妥善处理。但是假设我推送了一个破坏某些东西的提交,我想尽快恢复。将做以下工作:

git push production [id of commit to revert to]:master

IE 仍然会正确地将所有内容部署到 webroot 中吗?

【问题讨论】:

    标签: git deployment


    【解决方案1】:

    这应该可以按预期工作。您可能需要执行 git push +<commit>:master(注意 +)来替换生产主节点 HEAD 的错误提交。

    +<commit>:master 是一个参考规范,有关参考规范的更多信息,请参阅git push manpage。

    我建议在不需要强制推送到生产服务器的情况下更明确地还原:

    git revert <commit to revert>
    git push production
    

    或

    git reset --hard <commit to revert to>
    git push -f production
    

    见How to revert Git repository to a previous commit?

    【讨论】:

    • 如果是这样的话,那么这是做什么的:git push production [id of commit to revert to]:master
    • 抱歉,不知道我在说什么。
    • 我刚刚使用类似的设置进行了测试:一个“暂存”存储库,我们从该存储库向上游推送到一个裸露的“生产”存储库,该存储库带有一个接收后挂钩,可将文件更新到工作目录。运行git push +&lt;commit&gt;:master 作为回滚命令效果很好,将我的暂存目录留在最近的提交处,这样我就可以解决任何需要回滚部署的问题。谢谢!
    • 这很完美。然后,当你想部署到master分支的最新提交时,只需运行git push production master(与git push production +HEAD:master相同)
    猜你喜欢
    • 2015-12-08
    • 2011-03-28
    • 2012-11-13
    • 1970-01-01
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    相关资源
    最近更新 更多