Jesse Aldridge
Jesse Aldridge

Reputation: 8149

Why is `git blame` different from GitHub blame?

If I clone bootstrap: git clone https://github.com/twbs/bootstrap

And then do a git blame: git blame js/src/alert.js

It looks like every line was last touched by the same guy:

^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   1) import Util from './util'
^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   2)
^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   3)
^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   4) /**
^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   5)  * --------------------------------------------------------------------------
^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   6)  * Bootstrap (v4.0.0-alpha.6): alert.js
^7ffb61a (Patrick H. Lauke 2017-04-17 00:04:49 +0100   7)  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
...

But if I look at the blame view on GitHub I see a bunch of different people: https://github.com/twbs/bootstrap/blame/v4-dev/js/src/alert.js

What's with the discrepancy? Am I using git blame wrong?

Upvotes: 4

Views: 1510

Answers (3)

VonC
VonC

Reputation: 1324258

Another reason a git blame can differ from the GitHub blame view is the ability to ignore/exclude commits while doing the blame.

Ignore commits in the blame view (Beta)

It's now possible to ignore revisions in the blame view using a .git-blame-ignore-revs file in the root of your repository.

For more information, see "Ignore commits in the blame view".

https://docs.github.com/assets/cb-146929/images/help/repository/blame-ignore-revs-file.png -- Screenshot of a banner on the blame view linking to the .git-blame-ignore-revs file

Screenshot of a banner on the blame view linking to the .git-blame-ignore-revs file

Upvotes: 1

Kate Kasinskaya
Kate Kasinskaya

Reputation: 933

Just run git fetch --unshallow to have a full version of repo and this will fix the issue.

Here is a connected answer from another question https://stackoverflow.com/a/17937889/1758824

Upvotes: 6

Jesse Aldridge
Jesse Aldridge

Reputation: 8149

If you do a clone with limited depth, and the last change happened prior to the earliest revision pulled, git blame will show incorrect results (I assume it's showing the person who did the earliest known commit).

Upvotes: 8

Related Questions