- Local VCS
> stored in hardisk.
> no interaction/sharing
> lost if HDD fails
- Centralized VCS
> has a central remote repo & local copies
> commits and updates directly to remote.
> single point of failure
> eg: SVN
- Distributed VCS
> multiple repos
> remote server + local clones
> commit to local and then push and pull to/from remote.
> eg: Git
### Git * Git stores snapshots of the files (not diff updates). * Git allows for branching ( non-linear development) * Git is secure (SHA-1/MD5) * Git captures change history.
> * HEAD is like an active pointer.
git config --global alias.br branch
git br
is equivalent togit branch
now i.e br is an alias for branch command.
## Commands * ``` git init ``` : create a new local repo * ``` git branch ``` : current branch * ``` git diff ``` : show diff (unstaged files) * ``` git diff --stage``` : show diff (staged files)
-
git rm file.md
: remove file ( will get staged automatically). -
git mv f1.md f2.md
: move file -
$ git log --oneline --graph --all
: show branches -
git branch -d branch-name
: delete branch.
## Merge 1. ``` git checkout master``` : switch to master 2. ```git merge feature-branch```: merge feature branch onto master branch.
If master has no commits added since branching, then the head of the master will be fast forwarded.
If master has commits added then a new commit called merge commit will be added to master containing all changes from feature branch
## Rebase 1. ``` git checkout feature``` : switch to feature branch 2. ```git rebase master``` : rebase current branch (feature) onto master.
In rebase: Git
- finds the lowest common ancestor of both branches
- finds and stores the diffs/commits since the LCA to the head of feature
- adds the commits made in master branch (branch you are rebasing onto) to the feature branch
- replay the stored commits onto the feature branch
Finally the feature branch will be upto date with clean log containing changes from both.
Now we can do a fast forward merge.
Goal of Merging and Rebasing is same except that rebase provides a cleaner history with linear flow of commits.