How does git track file changes internally?

前端 未结 5 1985
孤街浪徒
孤街浪徒 2021-02-12 16:10

Could somebody explain how git knows internally that files X, Y and Z have changed? What is the process behind the scenes that recognizes when a file has not yet been added or h

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 16:48

    I found the following explanation helpful in a recent course, Git Essential Training by Kevin Skoglund, I followed at Lynda.com.

    Git generates a hash key composed of 40 hexadecimal characters by running an algorithm on the changes we have committed. For instance if we commit same set of changes at different occasions, we should get the same hash key.

    Additionally it keeps track of previous changes by keeping following meta information in each commit.

    1. Current Commit ID
    2. Parent Commit ID
    3. Author
    4. Message

    Each subsequent commit will refer to a parent commit, while the first commit will not have a parent(or a null/nil value). The following diagram would be helpful in this regard.

    Image credit : Git Essential Training by Kevin Skoglund at Lynda.com

    Git Essential Training by Kevin Skoglund at Lynda.com

提交回复
热议问题