5

I wanna see how much a repo changed in the last month on gitlab server side

cd /path/to/my/bare/repo.git/
git --git-dir . diff --shortstat "@{1 month ago}"
fatal: Unable to read log 'logs/refs/heads/master': No such file or directory

However it works fine in local checkout-ed working branch.

Is there a way to do this without too much hassle?

To avoid X-Y problem: I wanna run statistics through hundreds of repos on a Gitlab server

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
λq_
  • 362
  • 2
  • 10
  • Did you try in the repo directory without `--git-dir` ? – NoDataFound Sep 03 '14 at 07:38
  • `cd /path/to/bare/repo.git ; git diff --shortstat '@{1 month ago}'` should work. – knittl Sep 03 '14 at 07:42
  • What does `git --git-dir /path/to/my/bare/repo.git/ branch -a` states? – marbu Sep 03 '14 at 07:46
  • @NoDataFound yes. @knittl same error as my question. @marbu shows `* master` – λq_ Sep 03 '14 at 07:58
  • 2
    Simply running git diff on a bare repository give me this: `This operation must be run in a work tree`. I would not say it's not possible (gitk shows diff on bare repo but I guess it uses the SHA1 of commits to create the diff!). – NoDataFound Sep 03 '14 at 08:12
  • @NoDataFound That's what I guessed. I did a simple `strace git log` , it is indeed scanning through lots of SHA1, but `git diff` requires `logs/refs/heads/master` – λq_ Sep 03 '14 at 09:14

2 Answers2

4

Try and make sure, when diff'ing in a bare repo, to specify two commits (or diff would default to the working tree, which doesn't exist in a bare repo).

You don't need --git-dir .

However, using date when specifying a revision wouldn't work, as it is based on logs/refs, which doesn't exist in a bare repo

<refname>@{<date>}, e.g. master@{yesterday}, HEAD@{5 minutes ago}

A ref followed by the suffix @ with a date specification enclosed in a brace pair (e.g. {yesterday}, {1 month 2 weeks 3 days 1 hour 1 second ago} or {1979-02-26 18:30:00}) specifies the value of the ref at a prior point in time.
This suffix may only be used immediately following a ref name and the ref must have an existing log ($GIT_DIR/logs/<ref>).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    thanks, any solution to grab statistics? So far my best effort is to list out number of commits using `git log` but it's not as good as `git diff --shortstat` – λq_ Sep 04 '14 at 05:00
1

I found this question because I was getting fatal: This operation must be run in a work tree

If you are getting the error (in your bare repo):

[ec2-user@xxxxx git]$ git diff 81dcb182e4d16b6894b69a5b31133b8d8ff6c5e2
fatal: This operation must be run in a work tree

Ensure you are providing two commit hashes to diff.(as HEAD is a symbolic ref)

[ec2-user@xxxxx git]$ git diff <BASE COMMIT HASH> <UPDATE COMMIT HASH>

Eg.

[ec2-user@xxxxx git]$ git diff 11dcb182e4d16b6894b69a5b31133b8d8ff6c5ex 81dcb182e4d16b6894b69a5b31133b8d8ff6c5e2
Fostah
  • 2,947
  • 4
  • 56
  • 78