Does it track the process of my editing?
No.
It checks for the modifications by comparing the cached version (stored in the .git folder) and the current version.
Does vim leave some special files for git to achieve it?
No
... How does git know that I modified this line rather than doing deletion and insertion?
In short, it checks for the similarities as well as the differences in two files by using an algorithm that answers the longest common subsequence problem. It's important to know that diff
is not a command only present in git
- it is also a Linux/Unix command.
There are many algorithms that can be used to find the difference between two files, such as the Hunt–McIlroy algorithm and Myer's diff algorithm.
Rather than looking for a specific answer for git diff
, I suggest you look into the two above algorithms instead.
See this question for more details: Myers diff algorithm vs Hunt–McIlroy algorithm