38

I am wondering how I can target a specific commit SHA in Git for deployment, using Capistrano? It should be something like

cap deploy --version=<sha targeted>

Can't seem to find the answer to this after a lot of searching.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Scott Miller
  • 2,298
  • 3
  • 21
  • 24

4 Answers4

63

For Capistrano 2.9 until 3.0:

cap -S revision=80655da8d80aaaf92ce5357e7828dc09adb00993 deploy

For older versions of Capistrano, you can deploy a particular git commit/tree/branch/tag by doing this:

cap -s branch=80655da8d80aaaf92ce5357e7828dc09adb00993 deploy

In some cases there may be a need of specifying the Environment as an argument as well. production is just an example.

cap production -S revision=80655da8d80aaaf92ce5357e7828dc09adb00993 deploy
Don Giulio
  • 2,946
  • 3
  • 43
  • 82
molf
  • 73,644
  • 13
  • 135
  • 118
17

molf's answer didn't work for me (using capistrano 2.11.2). I had to use "revision" instead of branch, like this:

cap -S revision=80655da8d80aaaf92ce5357e7828dc09adb00993 deploy
eahanson
  • 369
  • 3
  • 4
14

Capistrano 3

In your deploy.rb or stage-specific file like config/deploy/production.rb

set :branch, ENV.fetch('REVISION', 'master')

This allows you to point to a specific git revision. It accepts a SHA but also anything that resolves to a real revision (e.g. git tag, annotated tag, or branch).

Use it on the command line by setting the REVISION environment variable, e.g.

bundle exec cap production deploy REVISION=80655da8d80aaaf92ce5357e7828dc09adb00993

bundle exec cap staging deploy REVISION=my-topic-branch
Dennis
  • 56,821
  • 26
  • 143
  • 139
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
1

ask :branch, 'master'

Prompts for input but defaults to 'master' if you press return.