introduction to git

40
Code management problems and VCS review. Introduction to git. Aleksey Asiutin

Upload: aleksey-asiutin

Post on 27-Jun-2015

835 views

Category:

Education


0 download

DESCRIPTION

Лекция посвящена основным принципам работа систем контроля версий и самой популярной на момент публикации такой системе - git.

TRANSCRIPT

Page 1: Introduction to git

Code management problems and VCS review.

Introduction to git.

Aleksey Asiutin

Page 2: Introduction to git

Old good version control system

Page 3: Introduction to git

Working on the website

index.htm

Page 4: Introduction to git

Collaboration

index.html

Page 5: Introduction to git

“Our team” HTML page

Page 6: Introduction to git

Austin Powers came into the play

Page 7: Introduction to git

File changes

Page 8: Introduction to git

Add James Bond

Page 9: Introduction to git

File changes

Page 10: Introduction to git

Dr. Evil is bad

Page 11: Introduction to git

Dr. Evil is good

Page 12: Introduction to git

Merge problem

Page 13: Introduction to git

File changes history

Page 14: Introduction to git

File changes history

Page 15: Introduction to git

VCS Features

● Backup and Recovery● Team Collaboration and Synchronization● History Log● Nonlinear Project Flow● Find a Guy to Blame :)

Page 16: Introduction to git

VCS

CVS

Subversion

mercurial

git

SourceSafe

Page 17: Introduction to git

Centralized VCS

Page 18: Introduction to git

Distributed VCS

Page 19: Introduction to git
Page 20: Introduction to git

Classic VCS working scheme

Page 21: Introduction to git

How git works with files

Page 22: Introduction to git

git install

http://git-scm.com/downloads

Page 23: Introduction to git

git configuration

Current repository configsgit action [arguments]

Current user global configsgit config --global user.name aasiutingit config --global user.email [email protected]

view all git configuration variablesgit config --list

Page 24: Introduction to git

git commands structure

general command structuregit action [arguments]

getting helpgit helpgit help <action>

Page 25: Introduction to git

Initialize git repositorygit init

Initialized empty Git repository in

/Users/spu/mygithub/.git/

Page 26: Introduction to git

Clone remote git repository

git clone \ https://github.com/aasiutin/twitter-

api-php.git

cloning into 'twitter-api-php'...

remote: Counting objects: 24, done.

remote: Compressing objects: 100% (16/16), done.

remote: Total 24 (delta 3), reused 21 (delta 2)

Unpacking objects: 100% (24/24), done.

Page 27: Introduction to git

File status Lifecycle

Page 28: Introduction to git

Check git statusgit status

# On branch master

nothing to commit (working directory

clean)

Page 29: Introduction to git

Add README, check git statusgit status

# On branch master

# Untracked files:

# (use "git add <file>..." to include in what

will be committed)

#

# README

nothing added to commit but untracked files

present (use "git add" to track)

Page 30: Introduction to git

Start tracking filesgit add README

$ git status

# On branch master

# Changes to be committed:

# (use "git reset HEAD <file>..." to unstage)

#

# new file: README

Page 31: Introduction to git

git add use casesgit add file1 file2 [file3 ...] #add list of files

git add *.txt #add all txt files in current directory

git add docs/*.txt #add all txt files in docs directory

git add docs/ #add all files in docs directory

git add "*.txt" #add all txt files in the whole project

git add --all #add all files

Page 32: Introduction to git

modify tracked files$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: README## Changed but not updated:# (use "git add <file>..." to update what will be committed)## modified: README

Page 33: Introduction to git

Commit changes to git$ git commit

# Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: README~~~".git/COMMIT_EDITMSG" 10L, 283C

$ git config --global core.editor [editor]

$ git commit -a -m “Commit message goes here”

Page 34: Introduction to git

Commit changes to git (2)$ git commit -m "Message goes here"

[master]: created 463dc4f: "Message goes here" 2 files changed, 3 insertions(+), 0 deletions(-) create mode 100644 README

Page 35: Introduction to git
Page 36: Introduction to git

Deleting and moving files$ git rm [filename]rm “[filename]”

$ git rm -f [filename] #remove changed file

$ git rm --cached [filename] #remove only from git, but not from filesystem

$ git mv old-name new-name #rename/move file

$ mv old-name new-name$ git rm oldname$ git add new-name

Page 37: Introduction to git

Undo changes$ git commit --amend #modify last commit

$ git reset HEAD [filename] #unstage file, keep changes

$ git checkout HEAD -- [filename] #discard all file changes and return last commit file state

Page 38: Introduction to git

Ignoring files$ cat .gitignore# a comment - this is ignored*.a # no .a files

!lib.a # but do track lib.a, even though# you're ignoring .a files above

/TODO # only ignore the root TODO file, not# subdir/TODO

build/ # ignore all files in the build/# directorydoc/*.txt # ignore doc/notes.txt, but not# doc/server/arch.txt

Page 39: Introduction to git

View changes and commit history$ git diff #view unstaged changes$ git diff --staged #view staged changes

$ git log #view commit history-p--stat--graph--pretty=oneline|short|full|fuller|format--since--untill--before--after

$ git log --pretty=format:”%h - %an” --before=”2 days ago” --after=”2013-04-25”

Page 40: Introduction to git