简体   繁体   中英

With PM2, how can I update / deploy the code if the git branch has been force pushed?

Starting with PM2 here.

Context: While we don't allow production or staging branches history to be modified (to be force pushed), we do allow it for dev or feature branches so that the commits can be squashed before review and moved to production.

But PM2 is trying to pull and so fails in that case. Is it possible to have PM2 fetch remote and then overwrite instead of trying to pull and apply changes?

As a side note: a few platforms such as Netlify, or Heroku, allow code to be force pushed and deploy. I'd like to reproduce it with PM2.

At the time of this writing, there is no clean way to do this.
PM2 does not allow us to choose how to merge.

But there is a work-around : there is an undocumented pre-deploy hook .
And we can use it to fetch the code that has been force-pushed.

You can write your deployment config to fetch the update like this:

  some-deployment:
    ref: origin/dev
    repo: ...
    path: ...
    pre-deploy: "git fetch && git reset --hard origin/dev"

For more details and maybe push the pm2 developers to offer a clean solution, here is this Github issue .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM