33
CHARLES UNIVERSITY IN PRAGUE http://d3s.mff.cuni.cz faculty of mathematics and physics Distributed Version Control Pavel Parízek [email protected]

Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

CHARLES UNIVERSITY IN PRAGUE

http://d3s.mff.cuni.cz

faculty of mathematics and physics

Distributed Version Control

Pavel Parí[email protected]

Page 2: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Key concepts

Nástroje pro vývoj software Distributed Version Control 2

Each developer uses a private local repository

clone: full mirror of some existing repository

Operations performed on the local repository

very fast, off-line

Synchronization

Operations push and pull

Exchanging code patches

Page 3: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Comparing distributed and centralized VCS

Nástroje pro vývoj software Distributed Version Control 3

Centralized

Everything visible in the central repository

Private branches (work) not possible

Distributed

Private repositories (and branches) useful for experimental development

Page 4: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Tools

Nástroje pro vývoj software Distributed Version Control 4

Git

Mercurial

Bazaar

Page 5: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Git

Nástroje pro vývoj software Distributed Version Control 5

Page 6: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Main features

Nástroje pro vývoj software Distributed Version Control 6

Versions: snapshots of the project (working dir)

Committed revisions form a direct acyclic graphMultiple “latest” versions (leaf nodes)

Each commit has an author and committerDistributing changesets via patches (email)

Whole repository stored in .git (files, metadata)

Confusing for most people (good for advanced users)Commands have names similar to SVN

Page 7: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Usage scenario

Nástroje pro vývoj software Distributed Version Control 7

Picture taken from http://git-scm.com/book/

Page 8: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Task 1

Nástroje pro vývoj software Distributed Version Control 8

Configure your identitygit config --global user.name

“<your full name>”

git config --global user.email

“<your email address>”

Stored in $HOME/.gitconfig

Page 9: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Basic commands

Nástroje pro vývoj software Distributed Version Control 9

Create repository in the current directory: git init

Print status of the working tree: git status

Start tracking new files: git add <work dir path>

Add files to the staging area: git add <path>

Commit staged modifications: git commit -m “...”

Print uncommitted unstaged changes: git diff

Print staged uncommitted changes:

git diff --staged

Automatically stage every tracked file and commit

git commit -a -m “...”

Revert modifications: git checkout -- <path>

Page 10: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

File status lifecycle

Nástroje pro vývoj software Distributed Version Control 10

Picture taken from http://git-scm.com/book/

Page 11: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Task 2

Nástroje pro vývoj software Distributed Version Control 11

Create repository in a specific directory

Create some new files (e.g., hello world)

Print current status of your repository andthe working directory

Stage all the new files

Print current status

Modify one of the files

Print current statusInspect differences from the previous invocation

Commit all staged modifications

Print current status

Page 12: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Managing files

Nástroje pro vývoj software Distributed Version Control 12

Make the given file untracked

git rm <work dir path>

Renaming file (directory)

git mv <old path> <new path>

Page 13: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Pick your changes

Nástroje pro vývoj software Distributed Version Control 13

Full interactive mode: git add -i

Select patch hunks: git add -p

Page 14: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Project history

Nástroje pro vývoj software Distributed Version Control 14

List all the commits

git log [-p] [-<N>] [--stat]

More options[--pretty=oneline|short|full|fuller]

[--graph]

[--since=YYYY-MM-DD]

[--until=YYYY-MM-DD]

[--author=<name>]

Page 15: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Task 3

Nástroje pro vývoj software Distributed Version Control 15

Try out file management commands (rm, mv)

Play with the “git log” commandExplore different parameters (-p, -<N>, --stat, --pretty, --graph)

Run the program “gitk” and try it

Make some changes to a particular file and use interactive staging

Page 16: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Using remote repositories

Nástroje pro vývoj software Distributed Version Control 16

Clone a remote repository in the current local directory: git clone <repo url>

Get recent changes in all branches from the remote repository: git fetch origin

Get recent changes in the “master” branch and merge into your working copy: git pull

Announcements via pull requests

Publish local changes in the remote repository: git push origin master

Page 17: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Branches in Git

Nástroje pro vývoj software Distributed Version Control 17

Page 18: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Branches in Git

Nástroje pro vývoj software Distributed Version Control 18

Branch: pointer to a node in the revision DAG

Default branch: master

Commit: branch pointer moves forward

Picture taken from http://git-scm.com/book/

Page 19: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

What happens after concurrent modification

Nástroje pro vývoj software Distributed Version Control 19

Picture taken from http://git-scm.com/book/

Page 20: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Branches in Git: commands

Nástroje pro vývoj software Distributed Version Control 20

Create new branch: git branch <name>

Switch to given branch: git checkout <name>

Shortcut: git checkout -b <name>

Merge branch into current working directory

git merge <branch name>

Deleting unnecessary branch

git branch -d <branch name>

List all branches: git branch [-a]

Current branch marked with *

Page 21: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Comparing branches

Nástroje pro vývoj software Distributed Version Control 21

git diff <branch 1>..<branch 2>

Compare heads of the two branches

Note the characters ‘..’

git diff <branch 1>...<branch 2>

Print changes on the branch 2 (e.g., master) since the branch 1 (feature) was created from it

Note the characters ‘...’

Page 22: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Three-way merge

Nástroje pro vývoj software Distributed Version Control 22

Common ancestor

Target branch

Source branch

Conflicts happen also with GitStandard markers <<<<<< ====== >>>>>>

Marking resolved files: git add

Graphical merging tool: git mergetool

Page 23: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Task 4

Nástroje pro vývoj software Distributed Version Control 23

Create new branch B and switch to it

Modify some files and commit them

Switch back to the master branch

Modify some files and then commit

Merge your branch B into the master

Delete the now unnecessary branch

Try switching branches with uncommitted changes in the working copy

Try graphical merging tool on some conflicts

Page 24: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

More advanced features

Nástroje pro vývoj software Distributed Version Control 24

Symbolic names of versionsHEAD, HEAD~1, HEAD^2

Using stack of unfinished changes (stashing)git reset

Several variants: clear the index, undo some commits

git rebase

Replaying changes done in a branch onto another branchVery powerful command but also tricky

Modifying committed historye.g., commit messages

Ignoring certain filesList patterns in the file .gitignore

Tagging: git tag

Bare repositoryNo working copy

Page 25: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Mercurial

Nástroje pro vývoj software Distributed Version Control 25

Basic principles: like Git

Simpler learning curve

Commands very similar

init, clone, add, commit, merge, push, pull

Better support for Windows

Page 26: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Work-flow models (cooperation)

Nástroje pro vývoj software Distributed Version Control 26

Page 27: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Work-flow models (cooperation)

Nástroje pro vývoj software Distributed Version Control 27

Anything possible technically with DVCS

“Network of trust” between developers

Examples

Single “central” repository

Multiple release repositories

Many public repositories

Total anarchy

Page 28: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Single “central” repository

Nástroje pro vývoj software Distributed Version Control 28

CentralRepository

PrivilegedDeveloperRepository

NormalDeveloperRepository

PrivilegedDeveloperRepository

NormalDeveloperRepository

Page 29: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Multiple release repositories

Nástroje pro vývoj software Distributed Version Control 29

MainRepositorydevelopment

DeveloperRepository

GUI branch

Release 1Repository

DeveloperRepository

DB branch

Release 2Repository

Release 3Repository

Page 30: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Many public repositories

Nástroje pro vývoj software Distributed Version Control 30

Linux kernel

OfficialRelease

MainDevelopment

integration

ModuleDevelopment

experiments

ModuleDevelopment

experiments

ModuleDevelopment

experiments

ModuleDevelopment

experiments

VendorRelease Vendor

Release

Page 31: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Total anarchy

Nástroje pro vývoj software Distributed Version Control 31

Repositoryno. 5

Repositoryno. 1

Repositoryno. 3

Repositoryno. 2

Repositoryno. 4

Page 32: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Links

Nástroje pro vývoj software Distributed Version Control 32

Git documentationhttp://git-scm.com/doc

Mercurialhttp://www.mercurial-scm.org/, http://hgbook.red-bean.com/

Repository servershttps://github.com/https://bitbucket.org/https://gitlab.com/

ToolsGit for Windows (http://msysgit.github.io/), TortoiseGit (Win), SmartGit (http://www.syntevo.com/smartgit/)TortoiseHg (Mercurial GUI, Windows)SourceTree (https://www.sourcetreeapp.com/, Git and Mercurial)

Page 33: Distributed Version Control - Univerzita Karlova...Nástroje pro vývoj software Distributed Version Control 11 Create repository in a specific directory Create some new files (e.g.,

Homework

Nástroje pro vývoj software Distributed Version Control 33

Assignment

http://d3s.mff.cuni.cz/~parizek/teaching/sdt/

Deadline

22.10.2018 / 23.10.2018