Diff

Being able to see the difference between two versions of a file is a critical function of version control. I made a small change to hello.bat and save as if I am working on a real project now.

If I run the command

git diff hello.bat

I get difference information on versions of the file. The minuses signify that something was removed from that version of the file, and the pluses signify that something is added to the file.

The green text with the + shows what was added.

The red text with the - shows what was subtracted.

GIT was always based on text files and will detect any change to any line. A small change to a line will be treated as if that line was deleted and then added as a new line.

If I type

git status

I can see what the status of these changes is and it even tells me what to do.

I can add the file and commit, or I can restore the previous version.

The diff command allows us to track back previous versions and see what changes have occurred to the current state. In the example below we can see unique hash value associated with this update. Go research what a hash value is, we will cover it in more detail in the networking module.

I record the hash,

To demonstrate how we can use this, I do an add and commit to store my second change.

I make another change, my third.

You can see the first hash was 9240d5d.

I can now see the difference between the current version of the file, and the version whose unique id I quoted.