问题
My local git repository is inside encrypted volume. I would like to be able to run git pull --all
only when the remote has new commits. However, I'm unable to use post-receive hook like here since I don't have the password to the encrypted volume. This means that even if the hook will be triggered I still don't know the password to mount the volume and to pull the new changes. So I'm looking for some other alternatives, one possible way I was thinking of was to ask the remote for the latest version SHA and compare it with the latest version SHA that the local copy knows, if they match I don't need to run pull command and if they don't match then I need to run the git pull command.
Is there a way I can run git rev-parse master
on the remote repository?
You can get more background about my problem here
回答1:
You can't do that literally.
There are two easy approximations:
- If you can use ssh (or some other accessor) on the remote, you can run
git rev-parse
and evengit rev-list
over there, which gets you as many SHA-1s as you want. - You can use
git ls-remote
to get the head SHA-1s from the remote (includingrefs/heads/master
). All that will tell you is "same" or "different", assuming you have the head SHA-1s locally. If they are different, you can't tell precisely why (though you can get probably-enough if you walk the local revs).
There's something weird about the question, though: you say the local repo is in an encrypted volume to which you do not have the password. If that's so, how do you know what the local heads are, and/or their history? They're recorded inside the repo.
回答2:
Is there a reason you don't want to pull? if it's because of the merge involved in pulling you can always issue git fetch
to get the headers and keeping the working copy unchanged
来源:https://stackoverflow.com/questions/19390283/can-i-issue-git-rev-parse-on-remote-repository-without-a-local-copy