Skip to content

Tell git that *.py files contain Python code, for use in word-diffs. #2133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2012

Conversation

bfroehle
Copy link
Contributor

By setting *.py diff=python in .gitattributes, git can know to:

  • Produce better hunk headers in the output of git diff
  • More accurately split words in git diff --color-words

For a neat demo, try something like, with and without this patch.

git show --color-words 31d0fe14

@Carreau
Copy link
Member

Carreau commented Jul 13, 2012

ha ! That's cool, I didn't even knew git has this option !
adding a *.js diff=javascript as it represent ~10% ?

@bfroehle
Copy link
Contributor Author

List of code types known to git:

  • bibtex suitable for files with BibTeX coded references.
  • cpp suitable for source code in the C and C++ languages.
  • csharp suitable for source code in the C# language.
  • fortran suitable for source code in the Fortran language.
  • html suitable for HTML/XHTML documents.
  • java suitable for source code in the Java language.
  • matlab suitable for source code in the MATLAB language.
  • objc suitable for source code in the Objective-C language.
  • pascal suitable for source code in the Pascal/Delphi language.
  • perl suitable for source code in the Perl language.
  • php suitable for source code in the PHP language.
  • python suitable for source code in the Python language.
  • ruby suitable for source code in the Ruby language.
  • tex suitable for source code for LaTeX documents.

@Carreau
Copy link
Member

Carreau commented Jul 13, 2012

waiting for javascript to be recognized then... thanks :-)

@bfroehle
Copy link
Contributor Author

AFAIK there isn't any hurt if it doesn't recognize the type, so I'll just include it now.

@minrk
Copy link
Member

minrk commented Jul 14, 2012

This looks good to me, but I am a bit confused - if git already knows about all of these kinds of files, why does it need to be told again in .gitattributes for it to have any effect? That seems a bit silly, but I trust that this is necessary.

@bfroehle
Copy link
Contributor Author

Yes, it's silly. .gitattributes just provides the mapping between file name (*.py) and the type of the file content (python). [So in other words, Git doesn't include a list of default file extensions].

@minrk
Copy link
Member

minrk commented Jul 16, 2012

gotcha, thanks! Merging away.

minrk added a commit that referenced this pull request Jul 16, 2012
Tell git that *.py files contain Python code, for use in word-diffs.

By setting `*.py diff=python` in `.gitattributes`, `git` can know to:
* Produce better hunk headers in the output of `git diff`
* More accurately split words in `git diff --color-words`
@minrk minrk merged commit 6d2b9e8 into ipython:master Jul 16, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Tell git that *.py files contain Python code, for use in word-diffs.

By setting `*.py diff=python` in `.gitattributes`, `git` can know to:
* Produce better hunk headers in the output of `git diff`
* More accurately split words in `git diff --color-words`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants