Everytime I add a property to a class with XML comments git thinks I added space below and a summary opening tag below instead of the of the one I wrote. For example, I added the property FirstName (line 16 to 20), but the git diff is (18 to 22). At first, I thought it was a normal behaviour. I think I've seen others git diff that does not have this behaviour.
12 /// <summary>
13 /// Date.
14 /// </summary>
15 public DateTime Date { get; set; }
16
17 /// <summary>
18 /// FirstName.
19 /// </summary>
20 public string FirstName { get; set; }
21
22 /// <summary>
23 /// LastName.
24 /// </summary>
25 public string LastName { get; set; }
Here is a picture for visual representation
It's not that bad, it just makes merge conflicts on properties more time consuming because I need to rewrite the summary tag.
Honestly, I don't even know what to do. I tried to write my code in different manners but can't get rid of this. I've search on internet but can't find a post about this problem.
If you just walk down the file one line at a time you can see that Git is right about where the difference starts. This is easiest to see if you put the old file and the new file side by side:
12 /// <summary> 12 /// <summary>
13 /// Date. 13 /// Date.
14 /// </summary> 14 /// </summary>
15 public DateTime Date { get; set; } 15 public DateTime Date { get; set; }
16 16
17 /// <summary> 17 /// <summary>
18 /// LastName. 18 /// FirstName.
19 /// </summary> 19 /// </summary>
20 public string LastName { get; set; } 20 public string FirstName { get; set; }
21
22 /// <summary>
23 /// LastName.
24 /// </summary>
25 public string LastName { get; set; }
The first line that differs is 18. Okay, then 19 is the same in both, but then 20 differs, and you can't have a one-line diff, so 18-20 are a new "hunk". Okay, but we already dealt with 16 and 17, so the next match is old 18 and new 23. Thus the diff is 18-22.
(I may be off by one but I think I've capture the general gist.)
I think the underlying issue here is that you are imagining that Git is going to tell you what happened. "Hey, these lines were moved down to make room for these other lines which were inserted." That is not how Git thinks. It is just playing "spot the difference"; it doesn't know or care about the mechanics of what you did from a human point of view.