문제

I have a small PHP library which I have written to support various web projects. Those projects are all in git, and the library is a submodule of each of those repos. The web projects are deployed with a git push, and the deployment script needs to have access to the library submodule repo to update the library.

Sometimes for any given project the library will have its own branch, until I merge those changes back to the master branch.

I've set up a bare remote repo for that library, and am able to push a library submodule to the remote repo. That works fine, and I can see those commits in the remote repo. However, when I try to deploy, those commits can't be found. In fact, if I clone the remote repo myself, I can't find those commits.

For example, the remote repo looks like this:-

git log --graph --oneline --date-order

* 9c9b880 (BRANCHA)
* e88ee92
* 07260c9
* 40b0963
*   35b6533 (tag: dev/0.0.2, master) Merge branch 'refs/heads/development'
|\  
| * ba3c1bd (HEAD, development)
| * eefa611
| *   1b87828 Merge branch 'refs/heads/BRANCHB' into development
| |\  
| | * 9078c1c (BRANCHB)
| |/  
| * 834e715
| * a000cd7
|/  
* 5985fc9 Initial commit

However, if I clone the remote repo as follows:-

git clone -b BRANCHA http://pathto/repo.git

The cloned repo then looks like:-

git log --graph --oneline --date-order

* 07260c9 (HEAD, origin/BRANCHA, BRANCHA)
* 40b0963 
*   35b6533 (tag: dev/0.0.2, origin/master) Merge branch 'refs/heads/development
|\  
| * ba3c1bd (origin/development, origin/HEAD)
| * eefa611
| *   1b87828 Merge branch 'refs/heads/BRANCHB' into development
| |\  
| | * 9078c1c (origin/BRANCHB)
| |/  
| * 834e715
| * a000cd7
|/  
* 5985fc9

If I do git pull I am Already up-to-date.

Why when I clone, do I end up on commit 07260c9, not commit 9c9b880, and why doesn't pulling bring down those later commits? Am I missing something about how remote bare repos should work, or should I be pushing to the bare repo in a different way?

도움이 되었습니까?

해결책

Props to @Chronial for pointing me in the right direction...

It turns out that git over ssh isn't quite the same as git over http. Maybe a git-fu expert can explain why, but the resolution is simple. On the remote repo:-

git update-server-info

Brings the repo as fetched over http in sync with the current state of the repo (as fetched over ssh).

It appears that this has to be run after every push to the remote repo, but that's as simple as renaming the file post-update.sample in the hooks directory of the repo to post-update, which runs the following script after every push:-

#!/bin/sh

exec git update-server-info
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top