25
High performance computing for non-programmers Lecture #10: Revision control: git Glib Ivashkevych  junior researcher, NSC KIPT

Lecture #10: Revision control with git

Embed Size (px)

Citation preview

Page 1: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 1/25

High performance computingfor non-programmers

Lecture #10:Revision control: git

Glib Ivashkevych

junior researcher, NSC KIPT

Page 2: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 2/25

Revision control

rationaleTrack changes

no more weird myfile , myfile-1 , myfile-new ,myfile-new-1 , myfile-very-last etc.

Collaborateallows many developers to work on the samecodebase

Multiple lines of devwork on stuff without affecting everything else

Page 3: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 3/25

Revision control

approachesCentralized

svn, Perforcesingle “central” repository

Distributedgit, mercurial (hg), bazaarmany independent repositories

Page 4: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 4/25

Revision control

gitDistributed , very fast, light branching model

Used byLinux kernel, Android OS, huge number of OSSprojects

Code hostingGithub, Bitbucket

Page 5: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 5/25

git

repositoriestracked files + metadata = repositoryCreate repository:> git init

Get a copy of existing repo:> git clone\https://github.com/PhtRaveller/kharkiv-hpc.git

git stores metadata in .git directoryinside the project

Page 6: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 6/25

git

repositories Working directory

snapshot of the projectStaging area

what to store in next commit

To see the current state:> git status

Page 7: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 7/25

git

commitsRecord of some state of the project ingit directory

Only staged files are committed

> git add myfile.py> git commit

Page 8: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 8/25

git

states of a file

untracked unmodified

modifiedstagedgit add

g i t c

o m m i

t < e d i t f i l e >

git add

git r m

Page 9: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 9/25

git

view history and compareView the history of commits:> git log

Useful keys: -p -<n> --stat--abbrev-commit --oneline

To compare diff erent states of a file:> git diff myfile.py

Page 10: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 10/25

git

branchesSeparate line of development

Actually, just a reference to particular commit→ lightweight

List branches:> git branch

Page 11: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 11/25

git

branchesCreate branch:> git branch <branch name>> git branch <name> <starting point>

Checkout branch:

> git checkout <name>Or all at once:> git checkout -b <name>

> git checkout -b <name> <point>

Page 12: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 12/25

git

mergesEventually, you’ll need to stitch branchestogether. This operation is called merge .

Merge br1 into br2 :> git merge br1 br2

Merge br1 into current branch:

> git merge br1

Page 13: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 13/25

git

conflictsBy default, git commits, if merge wassuccessful (always true for fast-forwardmerges). Use --no-commit to avoid this.

Sometimes, git fails when merging. This is

called merge conflict .

Resolve conflict by hand and commit

yourself in such a case.

Page 14: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 14/25

git

remotesYou can connect your repo to as many outsiderepositories, as you wish. Such repos arecalled remotes .

To add/remove remote:> git remote add <name> <URL>> git remote rm <name>

origin is a repository from which you cloned.

Page 15: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 15/25

git

pull & pushYou’ll definitely need to share your changes toremotes and get changes from remotes.

Pull changes:> git pull <remote> <branch>(git fetch is not the same)Push changes:> git push <remote> <branch>

Page 16: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 16/25

git

rewriting and undoingChange last commit:> git commit --amendRebase:> git rebase <many fun stuff here>Reset vs revert:> git reset <commit> <filename>

changes to the <commit> (--hard, --soft)

> git revert <commit>creates new commit, undoing <commit>

Page 17: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 17/25

git

workflows: centralizedshared repo

developer developer developer

Page 18: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 18/25

git

workflows: github style“official” repo

manager dev private dev private

dev public dev public

Page 19: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 19/25

git

configConfig files:.git/config~/.gitconfig/etc/gitconfigTo set option:> git config [--global|--file|--system]<option> <value>> git config --global user.email“[email protected]

Page 20: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 20/25

Github & Bitbucket

code hostingBoth allow you to store your code ingit repos (BB also can use hg)

Handy for sharing and collaborating.

Github has no free private repos.Bitbucket has.

Page 21: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 21/25

Version control

be politeWrite short , meaningful commitmessagesUse user.name & user.email

Don’t mess up with shared history

Never commit broken code

Page 22: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 22/25

Documentation

rationaleTrue jedi never comment their codeBullshit. Period.

You can forget, what you’d done one year ago.

You can generate documentation fromdocstrings.

Next developer will damn you, if you do not

comment your code.

Page 23: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 23/25

Documentation

rationale

Principle of least surprise:create reasonable, pragmatic andclean interfaces (and code, and so on)

Page 24: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 24/25

Documentation

SphinxDocumentation engine.

Generates html, pdf and many more.

Understands docstrings.

# pip install sphinx

> sphinx-quickstart

Page 25: Lecture #10: Revision control with git

8/13/2019 Lecture #10: Revision control with git

http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 25/25

Questions?