gitblamegit-blame

How to `git blame --ignore-revs-file` on a bare git repository


The command git blame --ignore-revs-file .git-blame-ignore-revs add.txt works on a non-bare repository locally on my machine but when I get the bare repository for the same repository locally and try the same command, the following happens:

git blame --ignore-revs-file .git-blame-ignore-revs add.txt
fatal: could not open object name list: .git-blame-ignore-revs

Also noted that it works when we pass the same content in a copied file sitting somewhere else in the file system. Eg: git blame --ignore-revs-file /tmp/.git-blame-ignore-revs add.txt works fine.

I thought this might be because its not able to find the path mentioned in bare repository and so I tried something like the following:

git blame --ignore-revs-file -- .git-blame-ignore-revs add.txt

but that resulted in : fatal: bad revision '.git-blame-ignore-revs'

Could anyone help me understand how do we pass file paths to options in git command while running it against bare repositories? Or is it just not possible?


Solution

  • edit: ah. I get it. You want to use the committed version of that file. Repo content in a bare clone ordinarily never exists as a separate file, history is sent in packs. You have to ask git to show itself the contents of that committed file:

    git blame --ignore-revs-file <(git show @:.git-blame-ignore-revs) add.txt
    

    or for purity points, howitzer-proof futureproofing and a few microseconds of speed,

    git blame --ignore-revs-file <(git cat-file blob @:.git-blame-ignore-revs) add.txt
    

    When I do this, it works:

    sh -x <<\EOD; rm -rf deleteme
    git init --bare deleteme; cd $_
    git update-index --add --cacheinfo 100000,$(git hash-object -w config),add.txt
    git --work-tree . commit -m-
    git log --oneline --name-status
    > .git-blame-ignore-revs
    git blame --ignore-revs-file .git-blame-ignore-revs add.txt
    EOD
    

    and when I do

    sh -x <<\EOD; rm -rf deleteme
    git init --bare deleteme; cd $_
    git update-ref HEAD $(git commit-tree -m - $(git mktree <&-))
    > .git-blame-ignore-revs
    git blame --ignore-revs-file .git-blame-ignore-revs add.txt
    EOD
    

    the error message is fatal: no such path add.txt in HEAD.

    So I think your first test really didn't have that ignore list present.