I want to fetch code using a particular SHA-id.This is what I am trying
- git:
repo: http://<git-url>/Vara-Internal/mongo-db-dev.git
dest: "{{ app_path }}/{{ app_dir }}"
version: "{{ GIT_TAG }}"
refspec: '+refs/heads/{{ GIT_TAG }}:refs/remotes/origin/{{ GIT_TAG }}'
update: yes
force: true
register: cloned
It throwing me this error
FAILED! => {"changed": false, "cmd": ["/usr/bin/git", "fetch", "--tags", "origin", "+refs/heads/dbde451f203a112d0838fb09bc19ed28bd231e6e:refs/remotes/origin/dbde451f203a112d0838fb09bc19ed28bd231e6e"], "failed": true, "msg": "Failed to download remote objects and refs: fatal: Couldn't find remote ref refs/heads/dbde451f203a112d0838fb09bc19ed28bd231e6e\n"}
(Note: I know very little about ansible, being just a casual user.)
Most (but not all) Git servers will not let you retrieve objects by hash IDs at all. Most servers require that the object have a name, such as refs/heads/master
(branch master
) or refs/tags/v1.1
(the tag named v1.1
).
If a server does allow retrieval by hash ID (see VonC's answer here ), you must not qualify the hash ID: it's not refs/heads/dbde451f203a112d0838fb09bc19ed28bd231e6e
bit rather simply dbde451f203a112d0838fb09bc19ed28bd231e6e
. That would become the src
part of a src:dst
refspec.
Typically you would use a tag name here, not a hash ID, but if your server does allow retrieval by hash ID, the refspec line would logically have to read:
refspec: '+{{ GIT_TAG }}:refs/remotes/origin/some-particular-name'
as it is not a good idea to use hash IDs as names (for several reasons, the main one being that you will confuse humans).
I used indirect method to the same.I have save commit ids in a file and added following code
- name: Reverting Changes
command: "git reset --hard {{ GIT_TAG }}"
args:
chdir: "{{ app_path }}/{{ app_dir }}"
when: build_type == "revert"
ie I took an extra variable which is build_type and checked whether this is for revert the changes.If it is then i read the commit id from my git information file and hard reset my branch.
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.