CodeMonkey CodeMonkey - 1 year ago 78
Bash Question

How do I get 'git log' in the terminal or using a shell script when not in a repository

I have Teamcity build agent, where I need to extract the

git log
from a repository. The trouble is, when my shell script runs, it's not in git repository, so
git log
doesn't work out of the box.

Does anyone know how to achieve this.

I have search the documentation, but I can't seem to find any way of doing it.

Problem solving so far

  1. When Teamcity "clones" a project from Github on to the agent, it doesn't actually clone the whole thing. So the
    working directory
    is not a repository.

  2. I do not have SSH access to github when running my shell script, which I need

Thanks in advance.


See accepted answer below.

Answer Source

My solution, ended up being as follows:

  1. Register SSH credentials to access Github on the TC Agent.

  2. git clone ssh:// /var/tmp/projectname_tmp

  3. cd to the directory /var/tmp/projectname_tmp

  4. git log >> output.file

For bonus points, you can extract from a given date like so:

  1. git log --since='2016-11-01 03:00' >> output.log
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download