Read more

Git blame: How to ignore white-space modifications

Arne Hartherz
December 19, 2012Software engineer at makandra GmbH

When doing a git blame, git will blame the person who added or removed white space in a line (e.g. by indenting), not the person who originally wrote the code.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Say git blame -w to ignore such white-space changes. You want this. \
Note that you can also use it when diffing: git diff -w.

Example

Consider this method, created by a user in commit d47bf443:

def hello
  'world'
end

^

$ git blame foo
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 2)   'world'
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 3) end

Now it's being changed to:

def hello
  if world?
    'world'
  else
    'universe'
  end
end

Here is how Git blames those lines with and without the -w switch:

$ git blame foo
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 2)   if world?
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 3)     'world'
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 4)   else
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 5)     'universe'
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 6)   end
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 7) end

^

$ git blame -w foo
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 2)   if world?
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 3)     'world'
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 4)   else
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 5)     'universe'
f5fae4c1 (Señor Foo     2012-12-19 14:47:36 +0100 6)   end
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 7) end
Posted by Arne Hartherz to makandra dev (2012-12-19 14:48)