Sie sind auf Seite 1von 25

High performance computing for non-programmers

Glib Ivashkevych
junior researcher, NSC KIPT

Lecture #10: Revision control: git

Revision control rationale


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

Collaborate
allows many developers to work on the same codebase

Multiple lines of dev


work on stuff without affecting everything else

Revision control approaches


Centralized svn, Perforce single central repository Distributed git, mercurial (hg), bazaar many independent repositories

Revision control git


Distributed, very fast, light branching model Used by Linux kernel, Android OS, huge number of OSS projects Code hosting Github, Bitbucket

git repositories
tracked files + metadata = repository
Create repository:
> git init

Get a copy of existing repo:


> git clone\ https://github.com/PhtRaveller/kharkiv-hpc.git

git stores metadata in .git directory inside the project

git repositories
Working directory snapshot of the project Staging area what to store in next commit To see the current state:
> git status

git commits
Record of some state of the project in git directory Only staged files are committed > git add myfile.py > git commit

git states of a file


untracked

git rm

unmodified

<edit file>

git add

gi

co

i m m

staged

git add

modified

git view history and compare


View the history of commits: > git log Useful keys: -p -<n> --stat --abbrev-commit --oneline To compare different states of a file: > git diff myfile.py

git branches
Separate line of development Actually, just a reference to particular commit lightweight List branches: > git branch

git branches
Create 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>

git merges
Eventually, youll need to stitch branches together. This operation is called merge. Merge br1 into br2: > git merge br1 br2 Merge br1 into current branch: > git merge br1

git conflicts
By default, git commits, if merge was successful (always true for fast-forward merges). 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.

git remotes
You can connect your repo to as many outside repositories, as you wish. Such repos are called remotes. To add/remove remote: > git remote add <name> <URL> > git remote rm <name> origin is a repository from which you cloned.

git pull & push


Youll definitely need to share your changes to remotes and get changes from remotes. Pull changes: > git pull <remote> <branch> (git fetch is not the same) Push changes: > git push <remote> <branch>

git rewriting and undoing


Change last commit: > git commit --amend Rebase: > 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>

git workflows: centralized


shared repo

developer

developer

developer

git workflows: github style


official repo dev public dev public

manager

dev private

dev private

git config
Config files: .git/config ~/.gitconfig /etc/gitconfig To set option: > git config [--global|--file|--system] <option> <value> > git config --global user.email mail@gmail.com

Github & Bitbucket code hosting


Both allow you to store your code in git repos (BB also can use hg) Handy for sharing and collaborating. Github has no free private repos. Bitbucket has.

Version control be polite


Write short, meaningful commit messages Use user.name & user.email Dont mess up with shared history Never commit broken code

Documentation rationale
True jedi never comment their code Bullshit. Period. You can forget, what youd done one year ago. You can generate documentation from docstrings. Next developer will damn you, if you do not comment your code.

Documentation rationale Principle of least surprise:


create reasonable, pragmatic and clean interfaces (and code, and so on)

Documentation Sphinx
Documentation engine. Generates html, pdf and many more. Understands docstrings. # pip install sphinx > sphinx-quickstart

Questions?

Das könnte Ihnen auch gefallen