GIT: how does git know the changes of a text file?

youkaichao

for example, by git diff file, we can know that we deleted 3 lines, inserted 1 line and modified 3 lines. but how can git achieve it ? Does it track the process of my editting? Does vim leave some special files for git to achiebe it?

I mean, if I modified one line, I can also say that I delete one line and insert one line. How does git know that I modified this line rather than doing deletion and insertion?

TwiN

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How does Git know that file was renamed?

From Dev

how does git know that file is staged for deletion?

From Dev

Does git ignore capitalization changes in file names?

From Dev

How does git track changes to files

From Dev

How does git calculate line changes?

From Java

How to stop tracking and ignore changes to a file in Git?

From Dev

How to ignore changes to a file when committing with Git?

From Dev

How to revert and fix the file changes in Git

From Dev

Detect changes to a file in Git

From Dev

git: how can i config git to ignore file permissions changes

From Dev

How does Git know I renamed a file when I did not, but intended?

From Dev

How to see the changes happened in a file, resulted by uncommitted changes git?

From Dev

How does 'git cherry-pick' find the file(s) to apply the changes to?

From Dev

MATLAB does not recognize".m" file changes after switching branches in git

From Dev

GIT diff and GIT status ignore changes of a file

From Dev

How does git know which version of a line to keep?

From Dev

How does git know which commit to check a submodule out at?

From Dev

How does git know which ssh key to use for its operations?

From Dev

How does git know the sha1 name of the pack files?

From Dev

How does git know which commit to check a submodule out at?

From Dev

How does git know which ssh key to use for its operations?

From Dev

Make git ignore file changes

From Dev

Git to show last changes of a file

From Dev

Git show whole file changes

From Dev

Git ignore local file changes

From Dev

Git log, showing file changes

From Dev

Make git ignore file changes

From Dev

Cant discard file changes in GIT

From Dev

how to know if a file was ever modified in the git repo after adding it

Related Related

  1. 1

    How does Git know that file was renamed?

  2. 2

    how does git know that file is staged for deletion?

  3. 3

    Does git ignore capitalization changes in file names?

  4. 4

    How does git track changes to files

  5. 5

    How does git calculate line changes?

  6. 6

    How to stop tracking and ignore changes to a file in Git?

  7. 7

    How to ignore changes to a file when committing with Git?

  8. 8

    How to revert and fix the file changes in Git

  9. 9

    Detect changes to a file in Git

  10. 10

    git: how can i config git to ignore file permissions changes

  11. 11

    How does Git know I renamed a file when I did not, but intended?

  12. 12

    How to see the changes happened in a file, resulted by uncommitted changes git?

  13. 13

    How does 'git cherry-pick' find the file(s) to apply the changes to?

  14. 14

    MATLAB does not recognize".m" file changes after switching branches in git

  15. 15

    GIT diff and GIT status ignore changes of a file

  16. 16

    How does git know which version of a line to keep?

  17. 17

    How does git know which commit to check a submodule out at?

  18. 18

    How does git know which ssh key to use for its operations?

  19. 19

    How does git know the sha1 name of the pack files?

  20. 20

    How does git know which commit to check a submodule out at?

  21. 21

    How does git know which ssh key to use for its operations?

  22. 22

    Make git ignore file changes

  23. 23

    Git to show last changes of a file

  24. 24

    Git show whole file changes

  25. 25

    Git ignore local file changes

  26. 26

    Git log, showing file changes

  27. 27

    Make git ignore file changes

  28. 28

    Cant discard file changes in GIT

  29. 29

    how to know if a file was ever modified in the git repo after adding it

HotTag

Archive