The VCS client of Android Studio

Nowadays, we can't imagine start a new software project without a version control system, between the different options available for a VCS, Git, without any doubt, has become one of the most popular systems among others like Subversion or Mercurial.

However, the learning curve that this kind of tools requires is often very high, since the huge variety of features and options that a version control system includes make it complex and powerful at the same time.

Both for the most experimented developers, and for the beginners, is important to use nice tools or a well enough customized environment in order to deal with the VCS in a effective and quick way.


Comparisons

Between the benefits we can find using a version control system, a powerful one is to compare files with their respective states over time. To that end, JetBrains includes one of the most powerful and intuitive diff / merge tools.

A good use of these tools allows to speed up the daily work since these comparisons are frequent when we are modifying code (adding, deleting or changing lines), besides reviewing it. Moreover, these modification are often hard to represent, so is not quite easy to find a good tool to show these changes clearly.

IntelliJ as a diff, merge tool

Starting with version 2016 of IntelliJ IDEA, JetBrains has included an interesting feature called Create command line launcher, which Android Studio has inherited in its 2.2 update.

This new feature allows the use of the diff / merge tools used in IntelliJ or Android Studio externally. In such a way that we could use it from command line or from our favorite third party VCS client.

Therefore, among other interesting situations, we could solve a conflict or compare different files using these external tools, which is really handy. As alternatives, tools like Kaleidoscope or Filemerge are also oriented to this purpose.

The VCS external client that I usually use is SourceTree, by Atlassian. To setting the Android Studio diff / merge tools as the default tool of SourceTree, we only need to set the binary created by the IDE (/user/local/bin/studio by default) in the settings section of SourceTree Settings/Diff, setting the external tool as other along the proper parameters.


Compare the current file with a branch

IntelliJ IDEA and Android Studio allow to compare the current open file in the editor with their respective version in a different branch. This may be interesting in various situations like reviewing code, verifying if a conflict has been solved properly, etc.

This feature, called Compare with branch, is available in the VCS menu or using find action ( ⌘ + A ) typing part of the feature name.

After choosing any branch which exists in the VCS (both local and remote versions), immediately a diff tool will be shown in order to compare the changes between branches.


Compare with a previous commit

The feature Compare with... will allow us, using a dialog, to choose a commit made previously in order to compare the changes made from that point to the current state of the file.

If, instead, we want to show the history of commits where the current file has been changing, we can use the feature Show history..., which will use a fixed panel shown at the bottom of the IDE to this purpose.


Handling the changes

Often, after modifying some files, may be useful to check which changes has been made from the last commit (changes that have not been committed yet). The feature local changes will put the focus in a bottom panel showing all local modifications that have not been committed.

At the local changes panel we can perform some features without taking your hands off the keyboard:

Show the diff tool with the changes made from the latest commit - ( ⌘ + D )



Revert changes - ⌥ + ⌘ + Z

Furthermore, this feature can be used in more contexts outside the log, using revert ⌥ + ⌘ + Z on any file, will show the revert dialog allowing to revert the most recent modifications done from the latest commit.

Note: Normally, the dialogs shown in IntelliJ/Android Studio can be closed with the shortcut tab + enter.


Log of the VCS

Despite, personally, I'm more with third party VCS clients like SourceTree (which it has a nice way for showing the log), Android Studio and IntelliJ also implement this feature, accessible looking for the feature Show VCS log via find action or reaching it under the VCS menu.


As advantages, being integrated inside the IDE it leverages all the navigations skills of IntelliJ. Therefore, we can interact with the log in a very easy and quick way with the keyboard firing different actions.

If we select certain commit we can access via find action_ ( ⇧ + ⌘ + A ) to interesting features related with the selected commit like resets, checkout, diffs using ( ⌘ + D ), etc.


VCS operations popup ( ⌥ + V )

We can show a dialog with the most commonly used operations working with a VCS like: commit, branches, stash, etc. Using the shortcut ( ⌥ + V ).


Committing

One of the key requirements using a VCS properly is to perform commits very frequently properly. A commit is considered atomic when all the modifications are related with one change semantically. Besides, a nice commit should express what is doing with a clear, concise and descriptive title.

However, it could be cumbersome, in environments where a third party VCS or poor customized command line are used, perform commits in a quick way.

Committing fast - ( ⌘ + K ) + (tab + enter)

Using the VCS client integrated in Android Studio or IntelliJ, utilizing the shortcut ( ⌘ + K ) + (⇥ + enter) we can have ready a commit in less than 5 seconds. Besides, there are a few interesting features that we can enable before committing, like code inspections, organize imports, etc.


GitHub integration

IntelliJ, Android Studio and probably among other JetBrains environments, we can take advantage of an integration with GitHub, after setting our credentials we will be able to use some useful features to interact with the social coding platform.

Get direct web links to the repository

Either from the file explorer or editing a file, the feature Open on GitHub, will open a browser with the remote version of that file. Moreover, if we run this feature with a selection of text, the same text will be highlighted in the link created with the GitHub version.

Create Pull Requests

There is a way to create pull requests directly from the editor, using the feature Create Pull Request (as usual accessible via find action), the IDE will prompt a dialog asking for the base branch and the candidate for merge. After filling the form, a pull request will be created at GitHub.

Create Gist

Similarly, we can create private, anonymous and public Gists on GitHub from Android Studio with the feature Create Gist.

References

How to write a commit message - Chris Beams.

Version Control Help - IntelliJ IDEA