# gt compare
The "gt compare" command will let you compare the current state of your files with a commit you previously made with the "gt save" command.
After executing "gt compare", you are prompted with a list of all the previous commits done to your project. You can navigate the list with the arrow keys and select the commit you want to compare with the enter key.
When a commit is selected, gitutor runs the following:
$ git diff <hashOfSelectedCommit>
Gitutor will then show you a string containing all the differences between the current state of your project and the selected commit.
If you wanted to do the same using only git, you would have to know the hash of the commit you want to compare or specify the number of commits behind to compare. Instead "gt compare" offers a way to easily select the commit you want to compare your project with.
# Understanding the output
Take for example the next snippet from example.py:
def divide(a,b): return a/b
Suppose we make the next changes:
def divide(a,b): if b == 0: return return a/b
The diff from these two versions would be the following:
The first line is a header that indicates that the diff is in git format. The prior version of the file is referenced as "a/example.py" and the current version is "b/example.py". It also shows that the red text with "-" marks preceeding it are lines from a/example.py and green lines with "+" marks are from b/example.py
The second line shows git's inner representation of the files and their user permissions
The blue text starting with "@@" indicate the lines in which the changes to the file were made.
It is in the format @@ -prior-version-file-range +current-version-file-range @@ [header].
The file-range is in the form <start line>,<number of lines>. If number-of-lines is not shown it means that it is 0.
The [header] part is an optional string showing the function or section of code that was modified.
The rest of the string is just text that was unmodified.
This commands offers an optional flags:
$ gt compare -h <hashOfSelectedCommit>
This flag tells gitutor to compare the current state of your project to the commit with the inputted hash. This command flag is usefull if you already know the hash of the commit you want to compare instead of going through the whole list of commits.