пятница, 1 ноября 2024 г.

Version Control System. GIT

A Version Control System (VCS) is a tool that helps you manage changes to files over time. It’s especially useful in coding and collaborative projects. 

The main goals of a Version Control System (VCS) are:

Backup and Restore: Think of VCS as a “save game” for your project. You can save different versions as you go and go back to any previous one if something breaks.

Synchronization:When working with others, VCS keeps everyone’s work up to date, so everyone has the latest version of the project.

Undo:If you make a mistake, VCS lets you undo changes or return to an earlier version of your work.

Track Changes:VCS keeps a record of every change, who made it, and when. It’s like a project diary that helps you understand how things evolved.

Sandboxing:You can try out new ideas without affecting the main project. This “safe zone” lets you test things freely.

Branching:You can create separate “paths” to work on different features or fixes. Each path is separate but can be merged back into the main project later.

Lock-Modify-Unlock and Copy-Modify-Merge are two approaches for managing file changes in Version Control Systems (VCS).


Git is a popular version control system that helps developers track and manage changes to their code. Originally created by Linus Torvalds in 2005 for Linux kernel development, Git has become widely used across software projects due to its speed, efficiency, and support for distributed, collaborative workflows.

  • git add: Moves changes to the Staging Area.
  • git commit: Commits changes from the Staging Area to the Local Repository.
  • git commit -am "Your commit message here": Stages and commits tracked changes only; ignores new untracked files.
  • git push: Sends local commits to the Remote Repository.
  • git fetch: Retrieves changes from the Remote Repository without merging.
  • git pull: Retrieves and merges changes from the Remote Repository.
  • git checkout: Switches branches or restore files to a previous state in the working area.
  • git clone: Copies a Remote Repository to your local machine.
  • git log: Displays commit history.
  • git restore <file>:Removes your changes and resets to the last commit. 
  • git restore --staged <file>: Unstages the file without discarding your changes.
  • git cleanremove untracked files from your working directory.
  • git reset <file_name>: Unstages file, keeps changes in working directory.
  • git reset --soft HEAD^Undo commit from local repository, keep changes in staging area.
  • git reset --mixed HEAD^Undo commit from local repository, keep changes in working directory.
  • git reset --hard HEAD^: Reset current branch to specific commit, discarding all changes in staging and working directory.
  • git revert HEADRevert the last commit from remote repository by creating a new commit.
  • git branchDisplay all local branches available.
  • git checkout -b <branch-name>: Create and switch to branch.
  • git checkout <branch-name>: Switch to branch.
  • git switch main git merge feature_branchSwitch to the target branch and merge changes from feature-branch into main.
  • git branch -D <branch-name>: Force deletes branch, even if unmerged.
  • git branch -d <branch-name>: Safely deletes branch if fully merged.
  • git remote -vLists all Git remotes with their fetch and push URLs displayed.
  • git remote remove origin: Removes the "origin" remote link, disconnecting from the remote repository.
  • git stash save --include-untracked "message": Temporarily saves your uncommitted changes, including untracked files, allowing you to switch branches or pull updates without losing your work.
  • git stash apply stash@{0}: Applies the most recent stash to your working directory.
  • git stash list: Shows a list of all stashed changes.
  • git stash drop: Deletes a specific stash.
  • git stash pop: Applies the most recent stash and deletes it from the stash list.
  • git merge main: Integrates changes from one branch into another, creating a merge commit.
  • git cherry-pick <commit-hash>: Applies specific commits from one branch onto another, selectively including changes. Switch to the target branch (the branch where you want to apply the commit).
  • git rebase main: Integrates changes from main into feature-branch while keeping a linear, clean.