107

Git in a Nutshell

Embed Size (px)

DESCRIPTION

Reference: http://www.slideshare.net/chacon/getting-git

Citation preview

Page 1: Git in a Nutshell
Page 2: Git in a Nutshell

• /* */

– browser_ver6/ browser_ver5/

Page 3: Git in a Nutshell
Page 4: Git in a Nutshell
Page 5: Git in a Nutshell
Page 6: Git in a Nutshell
Page 7: Git in a Nutshell
Page 8: Git in a Nutshell
Page 9: Git in a Nutshell
Page 10: Git in a Nutshell
Page 11: Git in a Nutshell
Page 12: Git in a Nutshell
Page 13: Git in a Nutshell
Page 14: Git in a Nutshell

Page 15: Git in a Nutshell

Page 16: Git in a Nutshell

Page 17: Git in a Nutshell

Page 18: Git in a Nutshell

Page 19: Git in a Nutshell

Page 20: Git in a Nutshell

Page 21: Git in a Nutshell

Page 22: Git in a Nutshell
Page 23: Git in a Nutshell
Page 24: Git in a Nutshell
Page 25: Git in a Nutshell
Page 26: Git in a Nutshell
Page 27: Git in a Nutshell
Page 28: Git in a Nutshell
Page 29: Git in a Nutshell
Page 30: Git in a Nutshell
Page 31: Git in a Nutshell
Page 32: Git in a Nutshell
Page 33: Git in a Nutshell
Page 34: Git in a Nutshell

git config --global user.name "Dan"

git config --global user.email

"[email protected]"

Page 35: Git in a Nutshell

– git init

– git clone

Page 36: Git in a Nutshell

cd project/

git init .

git add .

git commit –m "initial commit"

Page 37: Git in a Nutshell

[/tmp/foo] $ ls -lah

total 12K

drwxr-xr-x+ 1 Dan None 0 Feb 17 11:46 .

drwxrwxrwt+ 1 Dan root 8.0K Feb 17 11:46 ..

drwxr-xr-x+ 1 Dan None 4.0K Feb 17 11:19 .git

-rw-r--r-- 1 Dan None 0 Feb 17 11:46 Hello.txt

-rw-r--r-- 1 Dan None 0 Feb 17 11:46 README

.git/

Page 38: Git in a Nutshell

[/tmp/foo] $ ls -lh .git

-rw-r--r-- 1 Dan None 111 Feb 17 11:19 config

-rw-r--r-- 1 Dan None 73 Feb 17 11:19 description

-rw-r--r-- 1 Dan None 23 Feb 17 11:19 HEAD

drwxr-xr-x+ 1 Dan None 4.0K Feb 17 11:19 hooks

drwxr-xr-x+ 1 Dan None 0 Feb 17 11:19 info

drwxr-xr-x+ 1 Dan None 0 Feb 17 11:19 objects

drwxr-xr-x+ 1 Dan None 0 Feb 17 11:19 refs

Page 39: Git in a Nutshell

[/tmp/foo] $ git status

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

# modified: README

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# Hello

no changes added to commit (use "git add" and/or "git commit -a")

Page 40: Git in a Nutshell

[/tmp/foo] $ git status

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

# modified: README

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# Hello

no changes added to commit (use "git add" and/or "git commit -a")

Page 41: Git in a Nutshell

[/tmp/foo] $ git status

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

# modified: README

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# Hello

no changes added to commit (use "git add" and/or "git commit -a")

Page 42: Git in a Nutshell

[/tmp/foo] $ git status

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

# modified: README

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# Hello

no changes added to commit (use "git add" and/or "git commit -a")

[/tmp/foo] $ git add .

Page 43: Git in a Nutshell

[/tmp/foo] $ git status

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

# modified: README

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# Hello

no changes added to commit (use "git add" and/or "git commit -a")

[/tmp/foo] $ git add .

[/tmp/foo] $ git status

# On branch master

# Changes to be committed:

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

# new file: Hello

# modified: README

Page 44: Git in a Nutshell

[/tmp/foo] $ git status

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

# modified: README

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# Hello

no changes added to commit (use "git add" and/or "git commit -a")

[/tmp/foo] $ git add .

[/tmp/foo] $ git status

# On branch master

# Changes to be committed:

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

# new file: Hello

# modified: README

git commit

Page 45: Git in a Nutshell
Page 46: Git in a Nutshell

git add

Page 47: Git in a Nutshell

git add

Page 48: Git in a Nutshell

git add

git commit

Page 49: Git in a Nutshell

• git commit -a

• git mv git rm

Page 50: Git in a Nutshell

Page 51: Git in a Nutshell

– git add .

• tmp/*

log/*

build/*

.DS_Store

Thumbs.db

Page 52: Git in a Nutshell

– git add .

• tmp/*

log/*

build/*

.DS_Store

Thumbs.db

Page 53: Git in a Nutshell

[/tmp/foo] $ git add .

[/tmp/foo] $ git status

# On branch master

# Changes to be committed:

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

# new file: Hello

# modified: README

[/tmp/foo] $ git commit

Page 54: Git in a Nutshell

[/tmp/foo] $ git add .

[/tmp/foo] $ git status

# On branch master

# Changes to be committed:

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

# new file: Hello

# modified: README

[/tmp/foo] $ git commit -m 'add hello, refactor README'

Page 55: Git in a Nutshell

[/tmp/foo] $ git add .

[/tmp/foo] $ git status

# On branch master

# Changes to be committed:

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

# new file: Hello

# modified: README

[/tmp/foo] $ git commit -m 'add hello, refactor README'

[master 356bbef] add hello, refactor README

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 Hello

[/tmp/foo] $ git status

# On branch master

nothing to commit (working directory clean)

Page 56: Git in a Nutshell

[/tmp/git] $ git log commit 5673d695fcce217b26d1a5956c1184ff62dc74f1 Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:22 2011 -0800 Merge branch 'maint' * maint: parse_tag_buffer(): do not prefixcmp() out of range commit 759e84f07fd0fba2f3466b11b74146173d42cb6b Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:11 2011 -0800 Merge branch 'maint-1.7.3' into maint * maint-1.7.3:

Page 57: Git in a Nutshell

[/tmp/git] $ git log commit 5673d695fcce217b26d1a5956c1184ff62dc74f1 Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:22 2011 -0800 Merge branch 'maint' * maint: parse_tag_buffer(): do not prefixcmp() out of range commit 759e84f07fd0fba2f3466b11b74146173d42cb6b Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:11 2011 -0800 Merge branch 'maint-1.7.3' into maint * maint-1.7.3:

Page 58: Git in a Nutshell

[/tmp/git] $ git log commit 5673d695fcce217b26d1a5956c1184ff62dc74f1 Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:22 2011 -0800 Merge branch 'maint' * maint: parse_tag_buffer(): do not prefixcmp() out of range commit 759e84f07fd0fba2f3466b11b74146173d42cb6b Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:11 2011 -0800 Merge branch 'maint-1.7.3' into maint * maint-1.7.3:

Page 59: Git in a Nutshell

[/tmp/git] $ git log commit 5673d695fcce217b26d1a5956c1184ff62dc74f1 Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:22 2011 -0800 Merge branch 'maint' * maint: parse_tag_buffer(): do not prefixcmp() out of range commit 759e84f07fd0fba2f3466b11b74146173d42cb6b Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:11 2011 -0800 Merge branch 'maint-1.7.3' into maint * maint-1.7.3:

Page 60: Git in a Nutshell

[/tmp/git] $ git log commit 5673d695fcce217b26d1a5956c1184ff62dc74f1 Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:22 2011 -0800 Merge branch 'maint' * maint: parse_tag_buffer(): do not prefixcmp() out of range commit 759e84f07fd0fba2f3466b11b74146173d42cb6b Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:11 2011 -0800 Merge branch 'maint-1.7.3' into maint * maint-1.7.3:

Page 61: Git in a Nutshell

[/tmp/git] $ git log commit 5673d695fcce217b26d1a5956c1184ff62dc74f1 Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:22 2011 -0800 Merge branch 'maint' * maint: parse_tag_buffer(): do not prefixcmp() out of range commit 759e84f07fd0fba2f3466b11b74146173d42cb6b Author: Junio C Hamano <[email protected]> Date: Wed Feb 16 14:33:11 2011 -0800 Merge branch 'maint-1.7.3' into maint * maint-1.7.3:

Page 62: Git in a Nutshell

[/tmp/git] $ git show HEAD commit ebbc1b128825df6f7500f5e34836390b24ca4966 Author: Dannvix Chen <[email protected]> Date: Thu Feb 17 14:15:23 2011 +0800 improve README user experience diff --git a/README b/README index edb17cc..a40afab 100644 --- a/README +++ b/README @@ -1 +1,2 @@ Git test +Balah balah

Page 63: Git in a Nutshell

[/tmp/git] $ $ git blame git.c 85023577 (Junio C Hamano 2006-12-19 14:34:12 -0800 1) #include "builtin.h" 2b11e317 (Johannes Schindel 2006-06-05 19:43:52 +0200 2) #include "cache.h" fd5c363d (Thiago Farina 2010-08-31 23:29:08 -0300 3) #include "exec_cmd.h" fd5c363d (Thiago Farina 2010-08-31 23:29:08 -0300 4) #include "help.h" 575ba9d6 (Matthias Lederhof 2006-06-25 15:56:18 +0200 5) #include "quote.h" d8e96fd8 (Jeff King 2009-01-28 02:38:14 -0500 6) #include "run-command.h" 8e49d503 (Andreas Ericsson 2005-11-16 00:31:25 +0100 7) 4e10738a (Jeff King 2008-07-03 07:46:57 -0400 19) static int use_pager=-1; 4e10738a (Jeff King 2008-07-03 07:46:57 -0400 20) struct pager_config { 4e10738a (Jeff King 2008-07-03 07:46:57 -0400 21) const char *cmd; 9bad7233 (Jeff King 2010-11-17 12:04:12 -0500 22) int want; 9bad7233 (Jeff King 2010-11-17 12:04:12 -0500 23) char *value; 4e10738a (Jeff King 2008-07-03 07:46:57 -0400 24) }; 4e10738a (Jeff King 2008-07-03 07:46:57 -0400 25)

Page 64: Git in a Nutshell

Page 65: Git in a Nutshell

Page 66: Git in a Nutshell
Page 67: Git in a Nutshell
Page 68: Git in a Nutshell
Page 69: Git in a Nutshell
Page 70: Git in a Nutshell
Page 71: Git in a Nutshell
Page 72: Git in a Nutshell

[/tmp/foo] $ git branch * master

Page 73: Git in a Nutshell

[/tmp/foo] $ git branch * master

Page 74: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea

Page 75: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea

git branch newidea git checkout newidea

Page 76: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience'

Page 77: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience' [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)

Page 78: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience' [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)

Page 79: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience' [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)

Page 80: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience' [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)

Page 81: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience' [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)

Page 82: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience' [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)

Page 83: Git in a Nutshell

[/tmp/foo] $ git branch * master [/tmp/foo] $ git checkout –b newidea Switched to a new branch 'newidea' [/tmp/foo] $ git branch master * newidea [/tmp/foo] $ … vim newidea … [/tmp/foo] $ git commit –a –m 'improve README user experience‘ [/tmp/foo] $ git checkout master [/tmp/foo] $ git merge newidea Updating 356bbef..ebbc1b1 Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) [/tmp/foo] $ git branch –d newidea

Page 84: Git in a Nutshell

[/tmp/foo] $ git clone git://git.kernel.org/pub/scm/git/git.git

Initialized empty Git repository in /tmp/git/.git/

remote: Counting objects: 133887, done.

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

remote: Total 133887 (delta 100281), reused 132921 (delta 99480)

Receiving objects: 100% (133887/133887), 27.30 MiB | 76 KiB/s, done.

Resolving deltas: 100% (100281/100281), done.

[/tmp/foo] $ git push origin master

Page 85: Git in a Nutshell

[/tmp/foo] $ git clone git://git.kernel.org/pub/scm/git/git.git

Initialized empty Git repository in /tmp/git/.git/

remote: Counting objects: 133887, done.

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

remote: Total 133887 (delta 100281), reused 132921 (delta 99480)

Receiving objects: 100% (133887/133887), 27.30 MiB | 76 KiB/s, done.

Resolving deltas: 100% (100281/100281), done.

[/tmp/foo] $ git push origin master

Page 86: Git in a Nutshell

– git config

– git init

– git add

– git commit

– git status

– git log

– git tag

– git checkout

– git branch

– git merge

– git rebase

– git remove

– git fetch

– git pull

– git clone

– git push

– git diff

– git apply

– git format-patch

– git am

Page 87: Git in a Nutshell

Page 88: Git in a Nutshell
Page 89: Git in a Nutshell
Page 90: Git in a Nutshell
Page 91: Git in a Nutshell
Page 92: Git in a Nutshell
Page 93: Git in a Nutshell
Page 94: Git in a Nutshell
Page 95: Git in a Nutshell
Page 96: Git in a Nutshell
Page 97: Git in a Nutshell
Page 98: Git in a Nutshell
Page 99: Git in a Nutshell
Page 100: Git in a Nutshell
Page 101: Git in a Nutshell
Page 102: Git in a Nutshell
Page 103: Git in a Nutshell
Page 104: Git in a Nutshell
Page 105: Git in a Nutshell
Page 106: Git in a Nutshell

– git instaweb --httpd=webrick

– http://localhost:1234/

Page 107: Git in a Nutshell