5

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?

3 Answers3

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

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

I asked the question to understand if it is possible to used the checked in file in the repo.

Yes, but the syntax of git blame --ignore-revs-file is:

git blame --ignore-revs-file <file>  -- <file>

Meaning:

  • the first <file> (before the double-hyphen) is your .git-blame-ignore-revs
  • the second <file> (after the double-hypen) is your file to blame on.

By putting .git-blame-ignore-revs after --, you forced the git command to consider it as a "non-option argument".


In a bare repository, though, there is no working tree, so --ignore-revs-file has no actual file to reference.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

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.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • Curious to understand how the second option there `or for purity points, howitzer-proof futureproofing and a few microseconds of speed,` would save few microseconds. – Harish Gajapathy May 15 '23 at 17:15
  • `git show` is "porcelain", implemented by `git log` (it's basically `git log --no-walk -p`) which does its full setup, including scanning the configs for all its tweaks plus all of `git diff`s. – jthill May 15 '23 at 19:08
2

The same command works for me even with a bare repository. The prerequisite is that the file .git-blame-ignore-revs must exist in the current directory (where the bare repo exists).

Note that even if the file .git-blame-ignore-revs was checked into the repo, the file must be present in the file system in the path specified by the --ignore-revs-file option.

It's likely that you were getting the error simply because the file .git-blame-ignore-revs was absent in the current directory.

Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
  • `Note that even if the file .git-blame-ignore-revs was checked into the repo, the file must be present in the file system in the path specified by the --ignore-revs-file option.` This is already known. As I stated in the question, it works when the file is present somewhere else in the file system. I asked the question to understand if it is possible to used the checked in file in the repo. – Harish Gajapathy Mar 27 '23 at 17:36
  • 1
    No it's not possible, AFAIK. – Dheeraj Vepakomma Mar 28 '23 at 06:01