Living with Files More Happily

Post on 06-May-2015

405 views 5 download

Tags:

description

This is for a research group meeting on May 7, 2014.

Transcript of Living with Files More Happily

LIVING WITH FILES MORE HAPPILY

Yusuke Endo

VERSION CONTROL

WHAT WE DO

• Create files • Edit files • Save files • Delete files

Filesthe result ONLY

WHAT IS VERSION CONTROL?

Files with their HISTORY

PRIMITIVE WAY

awesome_euler.c awesome_runge_kutta.c blah_blah_v1.tex blah_blah_v2.tex

Error-prone• Repetition • What does v1 do? • Vulnerable to unintentional

changes/deletions

WHAT WE WANT

• Record who changes files what/when/why changes were made

• Review changes • Restore files to a past state

Git Logo by Jason Long

WHAT IS GIT?

•a version control system(VCS) •developed in 2005 by Linus Torvalds •used for Linux Kernel, Ruby On Rails, etc.

WHY GIT?

git is • Growing in share • Simple (compared to other VCSs) • Distributed • Fast

Git Logo by Jason Long

BASIC CONCEPTS

REPOSITORY

WORKING TREE Repository

Files

file

Project Directory

Meta Data

commits, etc.

COMMITFiles Commit

145ab3e5…snapshot

file

REPOSITORY

145ab3e5… 3eab3e51… a4661aca……

HEAD

TAG

145ab3e5… 3eab3e51… a4661aca……

v0.9.1

CHECKOUT

WORK TREE Repository

Files

file

Project Directory

checkout

STAGE / INDEX

Changed Files

file

Staged Files Commit

145ab3e5…stage

SUMMARY

Working Tree

Staged Files

Repository

checkout

stage

commitChanged Files

edit

Git Logo by Jason Long

BASIC COMMANDS

BASIC COMMANDS

Initialize a repository $ git init

Stage files $ git add <file>

Commit $ git commit [-m “message”]

Help $ git help

BASIC WORK FLOW

1. Edit Files 2. $ git add <file>

$ git commit -m “message”

BEST PRACTICECommit

Commit Message

1 | a short summary of the change 2 | 3 | if needed 4 | why you made the change 5 | …

• should be small • should not consist of changes which can be logically separable

OTHER USEFUL COMMAND

Show commit logs $ git log

Show the working tree status $ git status

Show difference between the latest commit and the working tree

$ git diff HEAD

DEMO

Git Logo by Jason Long

BRANCH

BRANCH

145ab3e5… 3eab3e51… a4661aca……

… …

testing

master

MERGE

145ab3e5… 3eab3e51… a4661aca…

testing

master

merge

CONFLICT

145ab3e5… 3eab3e51…

changes a.tex

changes a.tex

conflictmerge

REBASE

145ab3e5… 3eab3e51…

master

rebase

testing

Git Logo by Jason Long

BRANCH COMMANDS

COMMANDS

Show branches $ git branch

Create a branch $ git branch <branch>

Checkout a branch $ git checkout <branch>

Merge <branch> to the current branch $ git merge <branch>

Rebase <branch> to the current branch $ git rebase <branch>

DEMO

Git Logo by Jason Long

REMOTE

MERIT

• Backup • Easily Collaborate with others

DISTRIBUTEDCentralized VCS Distributed VCS

Working Tree

Working Tree

Repo Repo

Repo

commit checkout push pull

commit

checkout

remote

local

WHERE TO CREATE

Github

Bitbucket

Public Repository … free

Public / Private Repository … free up to 5 users

https://github.com/

https://bitbucket.org/

https://education.github.com/

• A git server you have • Storage services like Dropbox • Hosting Services

CLONE

Remote Repository

clone

Repository Working Tree

checkout

remote

local

PUSH

push

A B

A B C

Cremote

local

PULL

pull

A B

A B C

Cremote

local

Git Logo by Jason Long

REMOTE COMMANDS

COMMANDS

Create a repository without working tree $ git --bare init

Clone $ git clone <repository>

Push $ git push <remote> <branch>

Pull $ git pull <remote> <branch>

DEMO

ADDITIONAL INFORMATION

INSTALLATIONLinux$ yum install git-core

$ apt-get install git

Mac

$ brew install git

Windowshttp://msysgit.github.com/

Git may be already installed. To update by homebrew

INITIAL CONFIGURATIONgit config --global user.name “Your Name" git config --global user.email “mail@example.com“ !git config --global color.diff auto git config --global color.status auto git config --global color.branch auto git config --global color.grep auto !git config --global core.excludesfile $HOME/.gitignore git config --global push.default current

GIT CLIENT

CUI

GUI

• tig

• GitHub for <platform> • SourceTree • etc.

FURTHER READING

Pro Git http://git-scm.com/book/

Git from the bottom up http://ftp.newartisans.com/pub/git.from.bottom.up.pdf

THANK YOU!