Skip to content

Instantly share code, notes, and snippets.

@bhenderson
Last active October 4, 2017 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenderson/6cf91e0ac58a160fc34f2e11875c86e2 to your computer and use it in GitHub Desktop.
Save bhenderson/6cf91e0ac58a160fc34f2e11875c86e2 to your computer and use it in GitHub Desktop.
*.rb diff=ruby
[core]
attributesfile = ~/.gitattributes

Git supports an attributes file. A good read is https://git-scm.com/docs/gitattributes

Among the cool features is the ability to show ruby method definitions in the diffs.

The default behavior for ruby is to show the Class

Before

diff --git a/tmp/rubya.rb b/tmp/rubyb.rb
index 554bf890..fa453b1d 100644
--- a/tmp/rubya.rb
+++ b/tmp/rubyb.rb
@@ -8,6 +8,6 @@ class Foo
     # more context
     # more context

-    3
+    4
   end
 end

Add a .gitattributes file

After

diff --git a/tmp/rubya.rb b/tmp/rubyb.rb
index 554bf890..fa453b1d 100644
--- a/tmp/rubya.rb
+++ b/tmp/rubyb.rb
@@ -8,6 +8,6 @@ def my_foo
     # more context
     # more context

-    3
+    4
   end
 end

I personally set a global .gitattributes using ~/.gitconfig

class Foo
# lots of context
# lots of context
# lots of context
def my_foo
# more context
# more context
# more context
3
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment