Diff-viewing tools
When you’re working with medium to large files, or several of them at once, just viewing the changes between versions can tell you what you want to know more easily than looking at the whole file. There are a few ways to look at just the changes, the differences between the files, a.k.a. the diff.
diff
The simplest from the command line in Linux is the diff command.
diff file_1.py file_2.py
It shows a shorthand for which lines were added, which removed, which changed, in which files. It's space efficient, but takes a little effort to interpret.
vimdiff
vim also offers a way to compare the differences between two files.
vimdiff file_1.py file_2.py
This one is a little more intuitive, showing the two files side-by-side and highlighting characters that have been added, removed, or modified between the two.
Sublimerge
The prettiest that I have seen is Sublime's Sublimerge package. We will use that one for this course because it’s the easiest on the eyes.
Sublimerge is also notable because it lets you compare the same file across two different branches in a repository.
git diff
When you're working across branches or between commits, it's often convenient to see all the changes in all the files at once.
git diff branch_1 branch_2
does this for you at the command line.
As with other command line tools, the result is pithy and can take some practice to interpret, but it's very efficient.
GitHub compare
The version management website GitHub also has a fantastic tool for comparing code. It compares files across two branches. I'll include links to these as a convenient way to display the code changes in each exercise that is available to anyone with a web browser.
2 comments