Version Control System. DVCS, Git, tips and tricks. – Generatios – Purposes?



Version Control System. DVCS, Git, tips and tricks. – Generatios – Purposes?

0 2


version-control-system-introduction-with-git-n-github

Version Control System (VCS, RCS), Local and Centralized and Distributed version control, Terms,SVN overview, Git, Conflicts, Merging, Branching, Workflow, Installing, Configuring, Git basic commands, Github, Github Forks, Github Branches, Best Practices

On Github cursor-education / version-control-system-introduction-with-git-n-github

Version Control System. Introduction with github.

@itspoma / CURSOR Education

v1.8

will be prepared to perform simple tasks using a version control system
to learn more from other documents that may lack a high-level coneptual overview

Mercurial (Hg), Git, and Subversion (SVN)
            

Agenda

  • Version Control System (VCS)
  • SVN overview
  • Mercurial overview
  • Git \w commands
  • Branches, Merging and Conflicts
  • Github.com
  • GitHub Pages and Forks
  • Best Practices

VCS: Purposes

Version/Revision Control System

  • enables multiple people to simultaneously work on a single project
  • integrates work done simultaneously by different team members
  • gives access to historical versions of your project

програма для роботи з інф що змінюється

проблема: multiple developers
кожен - редагує свою копію файлів, і вибирає шо розшарити з іншими
проблема: декілька версій одного і того ж документа + історія

плюс: ви зможете повернутися до певної версії пізніше
плюс: локальні зміни одного не діють на інших

в розробці - для збер сорсів (код, граф ресурси, )
              

ex.: Wikipedia history of changes

              

ex.: history panel in Photoshop

ex.: Wordpress rollback post

ex.: Wordpress rollback post

Local version control

copy to separate directory(project-25-12-2015, backup-qweqwe15, New Folder 283, ...) problems? weaknesses? milestones?

cons: copy-paste, speed, manual

Local version control weaknesses?

Centralized version control diagram

problems? weaknesses? milestones?

single point of failure
uploads is slow
changes may break all
merging is painful
              

Distributed version control diagram

Розподілена
no network needed
fast (since local)
              

Terms

Repository

is a database of all the edits to, and/or historical versions (snapshots) of your project.local repository and the central (remote) repository

Working copy (checkout)

your personal (local) copy of repository

Checkout / Clone

action to copy a remote repository to your local

Commit

action, that you made to share your changes with other teammates. uploading your local changes to repository

Revision

a version of document

Update (git pull)

action, that you made to make your working copy up-to-date with remote repository

Changeset / Changelist

a named set of changes

Branching

Branch

a copy of repository

Trunk / Master

a main branch for work

Conflict

a case, when few users made not-similar changes in one file

Head

a latest version for branch

Merge

an action to combine independent changes to one version

Tag

a label for specific version of document

Distributed vs Centralized

Distributed and centralized version control

  • centralized example: Subversion
  • distributed (DVSC) more modern, runs faster, is less prone to errors, has more features, more complex to understand example: Mercurial, Git

централізовані
децентралізовані
is the number of repositories
              

there is just one repository.

  • You commit
  • They update

є один центральний репозиторій
              

there are multiple repositories

  • You commit (to your local)
  • You push (to remote)
  • They pull (from remote)
  • They update (to their local)

в кожного користувача є своя копія репозиторію на локалці
              

Merge: a diff

Merge

Conflicts

the final version is a merge of original version and edit. occurs when two different users make simultaneous, different changes to the same line of a file

RCS - pessimistic approach, "ci" and "co" actions CVS - multiple users, concurrent SVN - as tree Git - distributed, branching model, git-flow, rev checksums

Revision Control System - одна з перших реалізацій вона зберігає повну історію змін алгоритм дельта-компресії (зберігається тільки перша версія і всі міжверсійні зміни) бінарних файлів без компресії не має засобів для колективної роботи над набором файлів Concurrent Versions System Система одночасних версій колективна робота над файлами stores the history for each file assigns sequential version numbers to each file (1,2,3,..)

General Workflow

кожна система контролю версій має свою специфіку
              

Initial initialization

clone the project (tree of files/directories)from remote to local (filesystem)with specific version

The Daily Cycle

  • update the local copy to latest
  • make changes on local
  • sharing (saving) local changes with others

Git

is a:

  • essential professional tool
  • directory content management system
  • tree history storage system
  • content tracker

Why Git?

because:

  • simple
  • fast (save time)
  • no central repo (work offline, no network needed)
  • easy reverts
  • branching make life easier
  • ideal for development in team

Git: Evolution

  • 1991-2002 - Linux root, archives & patches (BitKeeper)
  • 2005 - Linux developers implemented own VCS (Git, Subversion)
  • 2007 - SVK
  • 2008 - Git (push/pull)
  • 2009 - Git (master, feature branches)
  • 2011 - Git (git flow, topic branch, rebase)

Git

Git: Directory structure

.git/

  • config files
  • hooks
  • index
  • object database
  • references

Git flow

цикле разработки через Github на командах разного размера

Git flow (simple)

  • branches: master & dev
  • master - stable, dev - working
  • detailed commit message (with issue ticket)
  • pull requests (for code review)
  • dev automatically to testing server
  • master release

Git flow (simple)

  • feature branches
  • release branches
  • hotfix branches
from where? to where?

Git: install

Git: configuring

$ git config

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

$ git config --list
$ git config user.name
              

Git: help

$ git help command
$ git command --help
$ man git-command
              

Git commands

Git: Creating an Empty Project

# initializes a directory as a Git repository
$ git init
              

Git: Getting a Project

# copy a git repository so you can add to it
$ git clone git://github.com/schacon/simplegit.git
              

Git: Basic Snapshotting

  • add
  • status
  • diff
  • commit
  • reset
  • rm, mv
  • stash

git add

adds file contents to the staging area

$ git status -s
?? README
?? hello.rb

$ git add README hello.rb
$ git add *.rb

$ git status -s
A  README
A  hello.rb

# edit & save the "README" file

$ git status -s
AM README
A  hello.rb
              

git status

adds file contents to the staging area

$ git status -s
AM README
A  hello.rb

$ git status -s
M  README
 D hello.rb
              

git diff

shows diff of what is staged and what is modified but unstaged

$ vim hello.rb
$ git status -s
 M hello.rb

$ git diff
diff --git a/hello.rb b/hello.rb
index d62ac43..8d15d50 100644
--- a/hello.rb
+++ b/hello.rb
@@ -1,7 +1,7 @@
 class HelloWorld
   def self.hello
-    puts "hello world"
+    puts "hola mundo"
   end
 end
              

git commit

records a snapshot of the staging area

$ git config --global user.name 'Your Name'
$ git config --global user.email you@somedomain.com

$ git add hello.rb 
$ git status -s
M  hello.rb

$ git commit -m 'my hola mundo changes'
[master 68aa034] my hola mundo changes
 1 files changed, 2 insertions(+), 1 deletions(-)

$ git status
# On branch master
nothing to commit (working directory clean)
              

git reset

undo changes and commits

$ git status -s
 M README
 M hello.rb

$ git add .
$ git status -s
M  README
M  hello.rb

$ git reset HEAD -- hello.rb 
Unstaged changes after reset:
M hello.rb

$ git status -s
M  README
 M hello.rb
              

git rm

remove files from the staging area

$ git rm hello.rb
              

Git: Branching and Merging

  • branch
  • checkout
  • merge
  • log
  • tag

Git: Sharing and Updating Projects

  • fetch, pull
  • push
  • remote

git remote

list, add and delete remote repository aliases

$ git remote
origin

$ git remote -v
origin  git@github.com:github/git-reference.git (fetch)
origin  git@github.com:github/git-reference.git (push)
              

git fetch

download new branches and data from a remote repository

              

git pull

fetch from a remote repo and try to merge into the current branch

$ git fetch github
remote: Counting objects: 4006, done.
remote: Compressing objects: 100% (1322/1322), done.
remote: Total 2783 (delta 1526), reused 2587 (delta 1387)
Receiving objects: 100% (2783/2783), 1.23 MiB | 10 KiB/s, done.
Resolving deltas: 100% (1526/1526), completed with 387 local objects.
From github.com:schacon/hw
   8e29b09..c7c5a10  master     -> github/master
   0709fdc..d4ccf73  c-langs    -> github/c-langs
   6684f82..ae06d2b  java       -> github/java
 * [new branch]      ada        -> github/ada
 * [new branch]      lisp       -> github/lisp
              

git push

push your new branches and data to a remote repository

$ git push github master
Counting objects: 25, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (25/25), done.
Writing objects: 100% (25/25), 2.43 KiB, done.
Total 25 (delta 4), reused 0 (delta 0)
To git@github.com:schacon/hw.git
 * [new branch]      master -> master
              

Git: Inspection and Comparison

  • log
  • diff

git log

filter your commit history

$ git log --author=Linus --oneline -5
81b50f3 Move 'builtin-*' into a 'builtin/' subdirectory
3bb7256 make "index-pack" a built-in
377d027 make "git pack-redundant" a built-in
b532581 make "git unpack-file" a built-in
112dd51 make "mktag" a built-iner
              

git diff

$ git diff v0.9 --stat
 README  |    2 +-
 ruby.rb |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
              

  Github is the place where copies of your code files will be stored.
  Your github account is more important than your resume.
  It holds the record of all the code you've written, which open-source projects you've contributed to and how.
  Your github account is your developer portfolio.
              

  • twitter
  • facebook
  • Yahoo!
  • jQuery
  • Ruby on Rails
  • node.js
  • symfony
  • mongodb
  • ...

GitHub Pages

http://pages.github.com/ http://your-name.github.io/your-repo/

TortoiseGit: right click

TortoiseGit: commit

GitHub: Forks

GitHub: Branching

TBD

GitHub alternatives

  • bitbucket
  • gitlab
  • ...

Version Control best practices

Advice: Use a descriptive commit message

write a good commit message to indicate the purpose of the changes

Advice: Make each commit a logical unit

each commit should have a single purpose and should completely implement that purpose

Advice: Avoid indiscriminate commits

make a commit with specific files

Advice: Incorporate others' changes frequently

work with the most up-to-date version of the files as possible

very frequently
to avoid conflicts
              

Advice: Share your changes frequently

share a logical unit of work with your colleagues as soon as possible

              

Advice: Coordinate with your co-workers

strive to avoid conflicts. to talk with teammates is the best way to avoid conflicts

              

Advice: Don't commit generated files

they aren't necessary in version control

              

Additional materials