If you have an Ansible playbook and you want to create a task that checks out a specific branch, this stackoverflow question says to do this:
- git:
repo: git://foosball.example.org/path/to/repo.git
dest: /srv/checkout
version: dev
Although version
can be the literal string "HEAD", a branch name, a tag, or a 40-character SHA-1 hash, this example assumes that you want to check out the HEAD branch. But what do you do if you have two branches, say a "dev" branch which is a child of a "master" branch, and you want to check out an older commit from the dev branch using a SHA-1 hash? How would you do that? If dev has not yet been merged into master, you would need to specify both the branch name "dev" and the hash. But Ansible doesn't seem to have a separate parameter to allow you do to this. There is a refspec
parameter but I'm not sure you can specify a hash in it. In this situation, would you just have to do a fetch
and checkout
using the Ansible command
task and specify the hash in the checkout task?