this post was submitted on 05 Aug 2023
10 points (100.0% liked)

Git

2910 readers
1 users here now

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Resources

Rules

  1. Follow programming.dev rules
  2. Be excellent to each other, no hostility towards users for any reason
  3. No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 1 year ago
MODERATORS
 

One of my main gripes regarding git is that it just generates diffs per line regardless of context or document format. This can be frustrating as it often leads to diffs that cover the end of a function declaration that was not touched and leaves out the end of a function that was just added.

Git supports diff options such as patience and histogram but , even though they mitigate some problems, they are still fallible.

So does anyone know if there is any way to get git to do context- or document format-sensitive diffs?

top 4 comments
sorted by: hot top controversial new old
[–] baturkey 5 points 1 year ago
[–] jnareb 3 points 1 year ago

With gitattributes you can configure custom diff driver and custom merge driver for a specific file type.

For example:

  • diff-tools include some tools that work as diff driver, but it is a bit undocumented in regards to what those diff drivers do, and for what files they should be used
  • nbdime tool for better diffing and merging of Jupyter notebooks can work as either diff driver, or as graphical diff interface (as difftool)
  • ...
[–] canpolat 1 points 1 year ago

I don't think Git has built-in support for that, but there seems to be some syntax/language aware diff tools that can be configured as the difftool.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

What are you looking for? What use case?

git config diff.tool allows you to configure and use/launch your own diff tools - GUI or not.
You can use any context or syntax aware diff tool with that.