1

If I have some code like

/**
 * blah blah blah
 */
...some codes...
/**
 * yadda yadda

And then I add

/**
 * blah blah blah
 */
...some codes...
/**
 * blah blah blah
 */
...some codes...

before the "yadda yadda" commanet, the git diff will show that I added:

 +  * blah blah blah
 +  */
 +  ...some codes...
 + /**

Is there a way to tell git, "hey, that's not right. Try again."? I know of --patience but that seems to just be for git diff and for the life of me it never works correctly. I know it's no super important, but it makes diffs and commit logs, especially on GitHub, much more clean.

jthill
  • 42,819
  • 4
  • 65
  • 113
Oscar Godson
  • 28,084
  • 40
  • 103
  • 191
  • I'm curious to hear why you classify this as "not right"? The change you made can be interpreted in multiple ways and git chose one that will yield the correct result inasmuch as it allows it to transform the first example into the second one. – Timo Geusch Aug 08 '13 at 00:58
  • I too have experienced the situation where the `--patience` flag doesn't seem to work as documented, I haven't figured out why yet though. –  Aug 08 '13 at 01:00
  • Technically, that's not what I added. I totally understand that the change could be interpreted differently, thats why my question is "can I tell git to look at it another way" – Oscar Godson Aug 08 '13 at 01:01
  • @OscarGodson you should re-title your question, because it seems that you want to change how diffs are presented to you, this doesn't look like it has anything to do with commits. –  Aug 08 '13 at 01:23
  • Found these resources that might be of interest in regards to `--patience`: (1) [What is `git diff --patience` for?](http://stackoverflow.com/questions/4045017/what-is-git-diff-patience-for/4045087#4045087), (2) [Patience Diff Advantages](http://bramcohen.livejournal.com/73318.html). –  Aug 08 '13 at 01:29

1 Answers1

5

The way Git stores files in the repository is on a whole-file basis. When you ask for a difference between two versions, Git retrieves both complete files from the repository1, and runs the diff algorithm between them. Unlike some other source control systems, Git does not calculate or store the differences between files at the time of commit.

This method has the advantage of easily changing the behaviour of the diff at the time you ask for it. For example, you have seen the --patience flag that uses a different diff algorithm to determine a (possibly) better patch between two files.

Because of the way files are stored in the Git repository, it is not possible to tell Git to somehow keep track of a custom diff alignment.

  1. Deep down in the Git repository, inside .pack files, Git uses various delta encoding methods to store differences between similar objects and thus reduce the size of the repository. However, this is on a lower level than the file storage and are not actual diffs between source files.
Greg Hewgill
  • 828,234
  • 170
  • 1,097
  • 1,237