git in a nutshell
DESCRIPTION
Reference: http://www.slideshare.net/chacon/getting-gitTRANSCRIPT
•
• /* */
•
–
•
– browser_ver6/ browser_ver5/
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
–
•
–
•
–
•
–
•
•
– git init
– git clone
cd project/
git init .
git add .
git commit –m "initial commit"
[/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/
[/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
[/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 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 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 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
# 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
[/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
git add
git add
git add
git commit
•
–
• git commit -a
• git mv git rm
•
–
•
– git add .
• tmp/*
log/*
build/*
.DS_Store
Thumbs.db
•
– git add .
• tmp/*
log/*
build/*
.DS_Store
Thumbs.db
[/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
[/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'
[/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)
[/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:
[/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:
[/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:
[/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:
[/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:
[/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:
[/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
[/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)
•
•
•
–
•
–
–
–
•
[/tmp/foo] $ git branch * master
[/tmp/foo] $ git branch * master
[/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] $ 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
[/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 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 * 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 * 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 * 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 * 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 * 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 * 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
[/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
[/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
•
– 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
•
–
•
–
•
–
–
•
– git instaweb --httpd=webrick
– http://localhost:1234/
•
•
•
•
•