Using Version Control
Using Version Control
Why Use Version Control in CDP?
Version control is a system that records changes to a file or a set of files over time so that you can recall specific versions later.
Version control allows you to revert any file back to a previous state, revert the entire project back to a previous state, track changes over time, see who last modified something that might be causing a problem (and why, given a good commit-message), which commit that introduced an issue and when, and more. Using a version control system also generally means that if things get broken or files get lost, you can easily recover by checking out the last good version. In addition, you get all this for very little overhead.
Version Control in CDP Studio
CDP Studio has version control support included. However, support depends on external tools that have to be installed and set-up beforehand:
- version control client programs
- version control remote repository (optional, for remote storage and collaboration with other people)
Installing the Git Version Control Client
Many different version control systems exist. CDP Studio has Git support included. Git is a advanced, fast, decentralized version control system.
To use Git as the CDP Studio versioning back-end, you must first install Git. Git installers can be downloaded and installed from Git homepage https://git-scm.com/
Note: Git must be found in the system PATH. Otherwise you must set the Git location in the CDP Studio menu Tools->Options->Version Control
.
Creating a Local Repository and Adding Files for Versioning
After the Git toolkit is installed, CDP Studio project or library source files can be added to be version controlled.
To use version control, a repository must be created at first. You can create a repository for a project or a library by using Tools->Git->Create repository
. Then the repository location must be chosen. Usually, a project folder is the best place for your project repository.
Note: The repository files are stored in a hidden sub-folder named .git
. If you delete this folder, you also delete your local copy of the repository.
When you have created the Repository, you can add your project files into it (or make the so called "initial commit"). To do so, choose menu Tools->Git->Commit...
, check [x] Select all
, enter some description under Description
and press Commit
.
Note: A good rule is to write a commit-message where the first line is a message that completes the sentence "If applied, this commit will " The following lines should shortly explain the changes done. If you use an issue-tracker, add a reference to the id at the bottom.
Committing Further Changes
After doing changes to your project or library, you can save (or "commit" in version control terms) the changes pretty much the same way as you did initial commit by choosing menu Tools->Git->Commit...
, checking the files you need to save (or add) history about, typing a description (log) of the change and pressing "Commit".
Note: Version control does not store changes to your files automatically. It is your responsibility to commit changes at any time a change history is needed.
Exploring Changes and Change History
You can explore changes made by using menu Tools->Git->Current file->Diff file...
(for the currently opened file) or Tools->Git->Current project->Diff project...
(to see changes to all files modified on current project). In the diff view you can revert any particular change in many ways, for instance by right-clicking and selecting context menu Revert chunk...
.
You can explore a log of changes by using menu Tools->Git->Current file->Log file...
(for currently opened file) or Tools->Git->Current project->Log file...
In the log view you can revert changes in many ways, for instance by using Reset to change...
Note: In Windows, if reverting does not work and outputs error messages (in CDP Studio Application Output pane) like Unable to launch "patch": Process failed to start: No such file or directory
, you have to set git.exe
as the patch tool in the menu Tools->Options->Environment->System->Patch command
.
Adding Remote Version Repository
You can get the benefits of versioning by using a local Git repository. However, to enable easy collaboration on the project or get a better backup, a remote repository should also be used. For a remote repository you can use your organization internal Git server or some public Git server service like GitHub or Bitbucket.
The remote repository address (that you can get from remote repository set-up) can be added to the project by using menu Tools->Git->Remote repository->Manage remotes
. After adding the remote, you can use Tools->Git->Remote menus
:
Push
- to send your local (commit'ed) repository changes to the remote repository (for others to review and merge)Pull
- to retrieve and merge in any changes made (by others) from the remote repository into your local repository.
Further Reading
Version control and Git are powerful and complex tools. To get more information you should study:
- The git tutorial at https://learngitbranching.js.org/
- Git manuals, starting from the "Git Book"
- Qt Creator and version control documentation at http://doc.qt.io/qtcreator/creator-version-control.html
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.