lecture #10: revision control with git
TRANSCRIPT
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
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
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
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
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
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
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
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
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
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
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>
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
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.
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.
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>
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>
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
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
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]”
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.
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
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.
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)
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
8/13/2019 Lecture #10: Revision control with git
http://slidepdf.com/reader/full/lecture-10-revision-control-with-git 25/25
Questions?