Suppose there is a file tracked by git. In this file, we changed a couple of lines, say at the beginning or in the middle.

Using the gitk utility, you can see what exactly has changed in the files, but there is a problem because case_1: sometimes through the utility, git only highlights a couple of lines that were deleted (-), and what was added (+), and sometimes it happened_2: it marks the contents of the entire file as (-) and replaces almost the same content plus improvements and marks ( +).

Question: in what cases does accident_1 work : and in what cases_2: and is it possible to foresee this somehow?

    2 answers 2

    The point is in line endings. Sometimes a text editor, sometimes a git changes the end of a line in the entire file. This happens when an inconsistent setting of the gita on different computers.

    Find the setting to ignore differences in line endings when comparing and use it.

    • OK thanks. Now it is clear where to dig. - I. Smirnov

    Chance_2 happens only if you forcibly deleted, and then added a file with the same name. Otherwise, this is random_1 , but all lines are actually changed. Just changed invisible characters, such as line breaks, spaces, tabs ...

    • Well, the real practice has shown that the accident_2 happens and when you change a little something in the file. Actually, therefore, the question arose. - I. Smirnov
    • Well, you yourself have marked as the best answer, explaining that this is the case_1 - Herman Borisov
    • Proceeding from the fact that I marked as the best answer, it is impossible to make an unequivocal conclusion: I had exactly the first case (both appeared and the files were not recreated manually). The answer I got was completely fine, unlike the answer I received from you. I do not see any reason to continue further discussion. Good luck. - I. Smirnov