Version Control Systems Support: Basic Concepts

Modern web development workflow can hardly be effective without a Version Control System (VCS) managing all your source code. It’s absolutely essential for team development or when your project grows large. VCS takes care of all your source code management, tracking changes made by developers and letting you: revert files to the previous revision; review code before applying changes and distributing it among the whole team; correct mistakes; develop in different branches; and do lots of other useful things.

PhpStorm (and other IDEs based on the IntelliJ Platform) provides integration with several Version Control Systems, including Git, Subversion, Mercurial and others. Integration includes both support for features specific for each VCS as well as a unified interface and management for common VCS tasks.

In this post we review the basics of working with VCS directly from the IDE.

This functionality is available in IntelliJ Idea, PhpStorm, WebStorm, PyCharm, RubyMine, AppCode.

A version control system is assigned to a project directory and/or additional directories that are part of or related to the project. In PhpStorm, you can easily clone a project from VCS and start working on it, or you can import your whole current project created locally to VCS.

Unified Version Control Functionality

PhpStorm provides a unified mechanism for working with Version Control Systems. However, some of them have unique features implemented which can simplify and speed up your work with that specific VCS.

For projects with VCS support enabled, the standard VCS actions (commit, update, revert, show differences and show history) are added to the main toolbar.

Most VCS-related functionality can be invoked from the VCS menu:

There are also a few hotkeys you’ll definitely find useful with version control systems. These include:

  • Alt+BackQuote (`) / Ctrl-V to invoke VCS quick popup,
  • Ctrl+K / Cmd-K to Commit project to VCS,
  • Ctrl+T / Cmd-T to Update project from VCS, and
  • Alt+Shift+C to View recent changes.

The following unified features are available for all VCSs:

  • Commit and update file/directory or an entire project,
  • Changelists support,
  • Next, Previous, Rollback, and Show Difference actions are available from the dedicated gutter bar in changed locations,
  • View revision history for file/directory,
  • Configuration of common version control system settings,
  • Advanced Version Control tool window, with multiple dedicated tabs: History, Status, Update Info, etc.

Please keep in mind that terminology differs among version control systems. For example, to share your work with others, you need to send your changes (or commits) to the remote repository. In Git you have to commit and then push while in Subversion it is enough to commit.

Changelists

A changelist is a set of changes in files that represents a change in the source code. The changes specified in a changelist are not stored in the repository until committed (pushed). Any changes made to the source files are automatically included in the active changelist. Initially, the Default changelist is active, but you can make any other changelist active.

In addition to the Default changelist, you can create new changelists, delete existing ones (except for the Default changelist), and move files between different changelists.

All modified, deleted, unversioned and other files are managed in the Changes tool window.

From this window you can:

  • Commit or push changelists,
  • Create new changelists,
  • Remove existing changelists and set the default changelists,
  • Revert modified files in changelists,
  • Add the unversioned files and directories to the VCS,
  • Move files between changelists,
  • Show differences on selected files,
  • Refresh the list of VCS changes,
  • Jump to the source code,
  • Shelve (stash) and unshelve (unstash) changes.

For Git a Log Tab is enabled. This tab shows the changes committed in all the branches of the local and remote repositories, or in a specific local or remote branch. You also can see branch graph on the left.

For other VCSs there is the Repository tab which shows the changes committed to the repository under the VCS roots within the current project. The Incoming tab (not available for Git and Mercurial) shows the changes committed to the repository by other team members, and not yet checked out locally. Both tabs display information stored in the history cache.

You can easily check differences between files (local vs repository, file versions in different branches or in different commits) and apply actions (if you are comparing with local file) to get the proper file as a result with all the changes applied.

Shelves, Stashes and Patches

Sometimes you need to urgently switch to a high-priority task, while some other task is not complete enough to be committed. In this case you might want to put some changes aside and continue working on a stable version.

Shelving is temporarily storing not yet committed changes in a dedicated shelf. Unshelving is returning postponed changes from a shelf to a pending changelist. You can shelve and unshelve both separate files and entire changelists or shelves.

For Git, stashing and unstashing actions are supported in addition to shelving and unshelving. These features have much in common; the major difference is in the way patches are generated and applied. Shelve can operate with either individual files or bunch of files, while Stash can only operate with a whole bunch of changed files at once. Here are some more details on the differences between them.

PhpStorm helps you create and apply patches to the source code. A patch is a file in the standard text format that has the *.patch extension and contains a list of differences between the two sets of source files. You can send it to your collaborators for code review or some other purpose, in case you don’t want to commit it directly to the VCS.

In addition to the VCS there is Local History feature tracking all the changes locally. See this post in order to get more information about it.

Using a unified interface for integrated version control systems, you will easily commit, push and perform any other actions in VCS you currently work with right from the IDE. If you don’t use a VCS yet, give it a try. It will keep your source code safe and clean and help your team work more productively.

Develop with pleasure!
– JetBrains Web IDE Team

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm, WebStorm and tagged , , , . Bookmark the permalink.

18 Responses to Version Control Systems Support: Basic Concepts

  1. Phil says:

    Good that you support VCS, but it is IMHO useless to replicate Git features and to not support (or faulty support) basic features like –amend at the same time.

    I always do (git) VCS operations in the command line, because PhpStorms Git features are too limited to be of any use.

  2. Vlad says:

    Its a great article, however there is still much work to do on VCS support, especially git. I have to say that the overlap of several phpstorm features and git features like shelve vs stash sometimes makes the understanding of the VCS part of the IDE kind of tricky.

    Also, some simple git operations were unavailable in the IDE, which caused me to dive into command line, and this would happen so often, that i just got used to work with the git command line.

    The only features i use from VCS currently is viewing diffs and merging. This is where i like the IDE better.

    Also submodules support … nevermind :)

  3. Timur says:

    Also git push -f would be nice to add as well.

  4. Jason Sylvestre says:

    I use Git Extensions, to be honest, this looks like a step backwards.

  5. Gregorio Ramirez says:

    These tools are very handy, I use the diff, push a lot. I also like how the editor highlights new & modified lines. The only valid complaint is the one suggesting more support for extra/missing features.

  6. Rafi B. says:

    Still trying to figure out how to manage Git submodules with PhpStorm. Let’s say I have a Git repo with several submodules in it, how would I commit a change on an inner submodule ?

  7. Pingback: Using GitHub without leaving PhpStorm | WebStorm & PhpStorm Blog

  8. I for one like the support for Mercurial (maybe because I don’t usually require “basic” functionality like amend, rebase, change laws of physics, time travel, you know, usual stuff) and it’s really great for simple workflow of pull – diff – commit – push. Except one tiny thing: somehow, while having zero problems with multiple repos anywhere else, after pressing “Commit and Push” the IDE suddenly forgets which repo I’ve just commited to and offers me to choose what to push myself. That’s a bit annoying.

  9. Dmitry Dulepov says:

    I read carefully but I still do not understand: what is the point of changelists? Why would I want to have multiple changelists? Never used them and after reading I do not see why would I want to use them.

    Any hints?

    • Phil says:

      My guess: Changelists are for people suffering from “Attention deficit-hyperactivity disorder” which are unable to complete a single task at a time.

      After all, I would prefer support for git stash and other advanced features of modern VCS as this seems to be more useful.

  10. Jason F says:

    Those of you who complain about the VCS tools — I personally see it as a nice way to enhance my ability to view diffs. The diff feature is really nice — and useful.

    I think the convenience features for making commits, etc are nice, but I actually prefer to just use GitG (linux) to review my commits & my own custom alias commands / grep, etc (i.e. command line) for my of my GIT handling.

    I may start trying to use the PHPStorm commit feature is nice, but I (sadly) prefer the very simple GitG view…

    I don’t think any tool can completely replace command-line GIT — not if you’re an advanced user.

    • Jason F says:

      Moderator — can you please remove this sentence from my first comment:
      I may start trying to use the PHPStorm commit feature is nice, but I (sadly) prefer the very simple GitG view…
      & replace it with:
      I (sadly) prefer the very simple GitG view vs PHPstorms commit feature / view.

Comments are closed.