+ All Categories
Home > Documents > Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern...

Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern...

Date post: 24-Jun-2020
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
47
Version Control Dr. Ewan Barr Swinburne University of Technology Computing for Physics Honours Lectures 01/06/2015
Transcript
Page 1: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Version ControlDr. Ewan Barr Swinburne University of Technology Computing for Physics Honours Lectures 01/06/2015

Page 2: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Problems

Managing code that is constantly changing

Working on projects with many collaborators

Experimenting with code without breaking it

Always being backed up

Page 3: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control
Page 4: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Mo Code Mo Problems

As code bases or documents grow, they become harder to manage

Python has thousands of developers writing core libraries (millions lines of source code)

Everyone works to their own schedule, impossible to synchronize all developers

Enter version control...

Page 5: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Version Control 101Version control only stores changes

Changes are stored sequentially

A document/code base becomes a history of changes

Page 6: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Version Control 101Multiple collaborators can work on the document

Versions can be merged

Page 7: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Version control provides you with a time traveling,

dimension hopping safe for all your code

Page 8: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Common Version Control Tools

ModernLegacy

Page 9: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Git

Modern distributed version control system

Developed for Linux kernel configuration control

Linux kernel 3.6 has 15.9 million lines of code

Cross platform

CLI or GUI

Slowly being adopted by the scientific community

Page 10: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Git Key Terminology

Repository (“Repo”) -- Project files and their histories

Commit -- An individual change made to the repo

Branch -- A parallel version of a repo

Working directory -- The actual directory where we edit

Page 11: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Git Key Terminology

Repository (“Repo”) -- Project files and their histories

Commit -- Different times

Branch -- Different dimensions

Working directory -- The actual directory where we edit

Page 12: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Hands on: setup a repo

Let’s setup our own repo:

mkdir vcs_code

cd vcs_code

git init

Next check on the status of the repo:

git status

Page 13: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Making commits

A commit records changes to one or more files in the repo.

To make a commit we must first add our changes to a staging area:

File in working directory

Page 14: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Hands on: adding a fileLet’s write a little GUI that prints something:

edit ui.py (add some code)

git add ui.py

git commit

Let’s check the status and also commit log:

git status

git log

Page 15: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Aside - Good commit messages

Credit: http://chris.beams.io/posts/git-commit/

Page 16: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Making a change

Let’s modify our GUI a bit:

edit ui.py (let’s change what is printed)

git add ui.py

git commit -m “Alter print output”

Check the log

git log

Page 17: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

The project history

1

2

Master

HEAD

Commits

Branch name

Points to head of current branch

Page 18: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

The project history

1

2

Master

HEAD~1

HEAD~1 “Head minus one”

points to last but one commit

Page 19: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Reverting changesAll previous commits can be referenced by HEAD~N

Alternatively specific commits can be referenced by their unique SHA key

Let’s “checkout” an older version of ui.py

git checkout HEAD~1 ui.py

We can undo this with:

git checkout HEAD ui.py

Page 20: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control
Page 21: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Branching

1 2 master HEAD

How do I mess around with existing code without breaking it

Working but I want to add a new feature

Page 22: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Branching

1 2 master

HEAD

How do I mess around with existing code without breaking it

feature

git checkout -b feature HEAD

Page 23: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Branching

1 2 master

HEAD

How do I mess around with existing code without breaking it

feature3 4

Do some development on “Feature” branch

Page 24: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Merging

1 2 master HEAD

Combining branches

feature3 4

Merge new feature back into “Master” branch

5

Why not just do the new feature in “Master”?

Page 25: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Merging

1 2 master HEAD

feature3 6

Merge new feature back into “Master” branch

7

Branching allows for simultaneous development

4 5

Combining branches

Page 26: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Merging

1 2 master HEAD

feature3 6

Merge new feature back into “Master” branch

7

In the “Master” branch the merge is seen a single big commit of the entire “Feature” branch

4 5

Combining branches

Page 27: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Rebasing

1 2 master HEAD

feature3 6

74 5

Combining branches

Rebasing is an alternative to merging

Base of “Feature” replaced by HEAD of “Master”

Page 28: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Rebasing

1 2 master HEAD

feature3 6

74 5

Rebasing is an alternative to merging

Base of “Feature” replaced by HEAD of “Master”

Combining branches

Page 29: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Rebasing

1 2 master HEAD

feature3a 6a

74 5

Rebasing is an alternative to merging

Rebased commits are then recommited to “Master”This gives a linear project historyAll “Feature” commits in “Master”

Combining branches

Page 30: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Changing branches

1 2 master HEAD

feature3 6

74 5

git checkout feature

Page 31: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Changing branches

1 2 master

HEADfeature3 6

74 5

git checkout master

Page 32: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Advanced branches

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Page 33: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

Page 34: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

Page 35: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

Clone Clone

Page 36: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Aside: Remotes

External repo’s are called “remotes”

When a you “clone” a repository, git automatically creates a remote called “origin”

“origin” points back to the original repository

Git stores local versions of all remote repos

These can be referenced like branches: “origin/master” is the master branch of the original repo

Page 37: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

edit -> add -> commit

How do we make user A’s edits available to user B?

Page 38: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

How do we make user A’s edits available to user B?

git push origin master

Page 39: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

How do we make user A’s edits available to user B?

git pull origin master

Page 40: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

What if both try to push?

Page 41: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

git push git push FailPass

User B must first pull and merge A’s changes before pushing to the same branch.

Page 42: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Collaborating

Central repo

User A local repo User B local repo

git push

A pull first fetches any remote changes then merges them into the local repository

git pull

Pass

Page 43: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Hands on: using GitHub

Let’s make a new online public repo

Push our vcs_code repo

Try and clone our online repo

Page 44: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Git workflows

Workflows are different methods of collaboration

Type of workflow used depends on:

Size of project

Type of project

Familiarity of collaborators with Git (important!)

Page 45: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Centralised Workflow

Central repo

User A repo

User B repo

User C repo

Central repo online

Each user has their own clone

User workflow:

pull -> add -> commit -> push

Only master branch on central repo

Page 46: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Forking WorkflowUser A

online repoUser B

online repo “central”

User C online repo

User A repo

User B repo

User C repo

Each user has their own online repo and local repo

One online repo is designated “central”

Users develop own repo

“central” user merges other repos using “pull requests”

Page 47: Version Control - Altervistaalex88ridolfi.altervista.org › pulsar_tutorials... · Git Modern distributed version control system Developed for Linux kernel configuration control

Resources

https://www.atlassian.com/git/tutorials

http://swcarpentry.github.io/git-novice/

http://gitolite.com/gcs.html

plus many, many more...

Do this!


Recommended