LoginSignup
5
5

More than 5 years have passed since last update.

deployする版と本番環境の版の差分をチェックする(git diff ワンライナー)

Last updated at Posted at 2013-11-14

やりたいこと

本番環境へdeployする際に「何が変るのか」はもちろん把握しているはずなのですが、意図していない commit が本当に混じっていないよね、という確認したくなりませんか?
また、アプリケーションコードをdeployする前にDBのmigrationを済ませておく必要がある場合、そのmigrationファイルを漏れなく列挙したい時もあると思います。そんな時のワンライナー。

前提環境

  • gitで版数管理している
  • capistrano で deploy している
  • 本番環境にssh接続できる

REVISIONファイルをチェックするためです。他のdeployツールでも同じようなファイルが配置されるのであれば、読み替えて応用できるはずです。

手順

変更コードをじっくり確認する

$ git diff `ssh user@app.server cat /app_path/current/REVISION`

変更されるファイルを列挙する

$ git diff --name-only `ssh user@app.server cat /path/of/app/current/REVISION`

migration ファイルを列挙する

$ git diff --name-only `ssh user@app.server cat /app_path/current/REVISION` db/migrate/

migrationファイルだけ先に up したい場合はこんな感じです。

$ git diff --name-only `ssh user@app.server cat /app_path/current/REVISION` db/migrate/ | xargs -I migrate_files scp migrate_files user@app.server:/app_path/current/db/migrate/
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5