Version control. Git.
Good day to all! π This post is dedicated to working with Git version control systems. Be patient and have coffee - there will be interesting and difficult material.
Version Control System (VCS)
π€ Are used when several people work on the same project.
Usually, the main project tree is stored in a local or remote repository, to which access is configured for project participants. When making changes to the project content, the version control system allows you to fix them, combine changes made by different project participants, roll back to any earlier version of the project, if required.
In classical version control systems, a centralized model is used, assuming a single repository for storing files. Most version control functions are performed by a special server. The project participant (user) receives the version of files he needs before starting work through certain commands. After making changes, the user places the new version in the repository. At the same time, previous versions are not deleted from the central repository and you can return to them at any time. The server can save not the full version of the modified files, but perform so-called delta compression β save only changes between successive versions, which reduces the amount of data stored.
Version control systems support the ability to track and resolve conflicts that may arise when several people work on a single file. You can merge (merge) changes made by different participants (automatically or manually), manually select the desired version, cancel the changes altogether or lock files for modification. Depending on the settings, the lock does not allow other users to get a working copy or prevents changing the working copy of the file by means of the OS file system, thus providing privileged access to only one user working with the file.
Version control systems can also provide additional, more flexible functionality. For example, they can support working with multiple versions of a single file, keeping a common history of changes up to the point of branching versions and their own change histories of each branch. In addition, information is usually available about which of the participants, when and what changes were made. Usually this kind of information is stored in the change log, access to which can be restricted.
Unlike the classical ones, in distributed version control systems, a central repository is not mandatory. Among the classic VCS, the most famous are CVS, Subversion, and among the distributed ones β Git, Bazaar, Mercurial. The principles of their work are similar, they differ mainly in the syntax of the commands used in the work.
Examples of using git
- π¬ The Git version control system is a set of command-line programs. They can be accessed from the terminal by entering the git command with various options.
- π Due to the fact that Git is a distributed version control system, a backup copy of the local storage can be made by simple copying or archiving.
For example, below is a description of the main commands of the git system.
Description of the main commands of the git system
Command | Action |
---|---|
git init |
Creating the main repository tree |
git pull |
Getting updates (changes) of the current tree from the central repository |
git push |
Sending all changes made to the local tree to the central repository |
git status |
View the list of modified files in the current directory |
git diff |
View current changes |
git add . / git add <filename> / git rm <filename> |
Saving current changes |
git commit / git commit -am "commit description" |
Saving added changes |
git checkout -b_name |
Creating a new branch based on the current one |
git checkout branch name |
Switching to some branch |
git push origin_name |
Sending changes of a specific branch to the central repository |
git merge --no-ff_name |
Merging a branch with the current tree |
git branch -d branch_name |
Deleting a local branch already merged with the main tree |
git branch -D branch_name |
Forced deletion of a local branch |
git push origin :branch name |
Deleting a branch from the central repository |