git log over ssh remote repository

2019-04-02 10:14发布

问题:

I want to create a git (web) browser, hence I need to iterate over commits (git log) on remote repository which is on ssh connected machine. My repo is quite big and constantly changing, therefore I will be interested in not fetching changes locally only to git log them.

I have tried with:

git remote add origin ssh://example.net/repo
git checkout -b master --track origin/master

and it failed :\

Any hints how to do that?

回答1:

You could push the log to the web server using a hook. On the repository host create a script:

repo.git/hook/post-receive

where repo.git is your repository path. If anyone pushes to this repository the hook will be triggered and it could dump git log to file and send it to the web server over ssh.

The solution has advantage that anyone having access to web server wouldn't get immediate access to the repository.



回答2:

On the remote machine, cd to your repository and do a git instaweb. That will start up a web server that you can access which will contain logs and all other things which are generally used. git help instaweb for details.



回答3:

You can try to run git log over ssh in a cronjob:

ssh example.net git --git-dir=repo log > /tmp/repo.log

This way you don't need to create local repository copy. This assumes you have ssh keys set up and feel safe with this configuration (someone with access to web server could potentially gain access to the repository).



回答4:

The reason you get an error with the commands that you quote is because you need to run git fetch origin after adding the remote in order to create the remote-tracking branch origin/master.



回答5:

Having to fetch to do git log does not always work. - I have a large repo that I rarely update so I only clone when I need to make a change. But I'd like to keep up with changes to it. - I just pushed. I'd like to double check the remote repo got my change. and I dont have ssh access but do have git access to the machine.

It seems obvious that:

GIT_DIR=node:/path/to/repo.git git log

should work for a restricted set of git log switches.

It's one of the few holes in git today, IMHO.



回答6:

If you would like to run git log localy you will need to clone the repository (isn't that what you were trying to do?):

git clone example.net/repo

Disadvantage is that it will take space to store it on the web server, but any future pull will download only new changes and may be quite fast and will depend on size of changes:

cd repo
git pull

You could make the pull either in crontab or even trigger it from repository host using hook to update it only when needed.