Living with Files More Happily

47
LIVING WITH FILES MORE HAPPILY Yusuke Endo

description

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

Transcript of Living with Files More Happily

Page 1: Living with Files More Happily

LIVING WITH FILES MORE HAPPILY

Yusuke Endo

Page 2: Living with Files More Happily

VERSION CONTROL

Page 3: Living with Files More Happily

WHAT WE DO

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

Filesthe result ONLY

Page 4: Living with Files More Happily

WHAT IS VERSION CONTROL?

Files with their HISTORY

Page 5: Living with Files More Happily

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

Page 6: Living with Files More Happily

WHAT WE WANT

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

• Review changes • Restore files to a past state

Page 7: Living with Files More Happily

Git Logo by Jason Long

Page 8: Living with Files More Happily

WHAT IS GIT?

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

Page 9: Living with Files More Happily

WHY GIT?

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

Page 10: Living with Files More Happily

Git Logo by Jason Long

BASIC CONCEPTS

Page 11: Living with Files More Happily

REPOSITORY

WORKING TREE Repository

Files

file

Project Directory

Meta Data

commits, etc.

Page 12: Living with Files More Happily

COMMITFiles Commit

145ab3e5…snapshot

file

Page 13: Living with Files More Happily

REPOSITORY

145ab3e5… 3eab3e51… a4661aca……

HEAD

Page 14: Living with Files More Happily

TAG

145ab3e5… 3eab3e51… a4661aca……

v0.9.1

Page 15: Living with Files More Happily

CHECKOUT

WORK TREE Repository

Files

file

Project Directory

checkout

Page 16: Living with Files More Happily

STAGE / INDEX

Changed Files

file

Staged Files Commit

145ab3e5…stage

Page 17: Living with Files More Happily

SUMMARY

Working Tree

Staged Files

Repository

checkout

stage

commitChanged Files

edit

Page 18: Living with Files More Happily

Git Logo by Jason Long

BASIC COMMANDS

Page 19: Living with Files More Happily

BASIC COMMANDS

Initialize a repository $ git init

Stage files $ git add <file>

Commit $ git commit [-m “message”]

Help $ git help

Page 20: Living with Files More Happily

BASIC WORK FLOW

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

$ git commit -m “message”

Page 21: Living with Files More Happily

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

Page 22: Living with Files More Happily

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

Page 23: Living with Files More Happily

DEMO

Page 24: Living with Files More Happily

Git Logo by Jason Long

BRANCH

Page 25: Living with Files More Happily

BRANCH

145ab3e5… 3eab3e51… a4661aca……

… …

testing

master

Page 26: Living with Files More Happily

MERGE

145ab3e5… 3eab3e51… a4661aca…

testing

master

merge

Page 27: Living with Files More Happily

CONFLICT

145ab3e5… 3eab3e51…

changes a.tex

changes a.tex

conflictmerge

Page 28: Living with Files More Happily

REBASE

145ab3e5… 3eab3e51…

master

rebase

testing

Page 29: Living with Files More Happily

Git Logo by Jason Long

BRANCH COMMANDS

Page 30: Living with Files More Happily

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>

Page 31: Living with Files More Happily

DEMO

Page 32: Living with Files More Happily

Git Logo by Jason Long

REMOTE

Page 33: Living with Files More Happily

MERIT

• Backup • Easily Collaborate with others

Page 34: Living with Files More Happily

DISTRIBUTEDCentralized VCS Distributed VCS

Working Tree

Working Tree

Repo Repo

Repo

commit checkout push pull

commit

checkout

remote

local

Page 35: Living with Files More Happily

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

Page 36: Living with Files More Happily

CLONE

Remote Repository

clone

Repository Working Tree

checkout

remote

local

Page 37: Living with Files More Happily

PUSH

push

A B

A B C

Cremote

local

Page 38: Living with Files More Happily

PULL

pull

A B

A B C

Cremote

local

Page 39: Living with Files More Happily

Git Logo by Jason Long

REMOTE COMMANDS

Page 40: Living with Files More Happily

COMMANDS

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

Clone $ git clone <repository>

Push $ git push <remote> <branch>

Pull $ git pull <remote> <branch>

Page 41: Living with Files More Happily

DEMO

Page 42: Living with Files More Happily

ADDITIONAL INFORMATION

Page 43: Living with Files More Happily

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

Page 44: Living with Files More Happily

INITIAL CONFIGURATIONgit config --global user.name “Your Name" git config --global user.email “[email protected]“ !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

Page 45: Living with Files More Happily

GIT CLIENT

CUI

GUI

• tig

• GitHub for <platform> • SourceTree • etc.

Page 46: Living with Files More Happily

FURTHER READING

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

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

Page 47: Living with Files More Happily

THANK YOU!