Slide 1

Slide 1 text

Git ChiaChia Lee Rails developer@Polydice Inc. [email protected] 11年9月30日星期五

Slide 2

Slide 2 text

What is Git? 11年9月30日星期五

Slide 3

Slide 3 text

Git is... 11年9月30日星期五

Slide 4

Slide 4 text

Git is... • distributed version control system • with complete history • not dependent on network access or a central server • Mercurial, Bazaar, Subversion, CVS, Perforce, and Team Foundation Server 11年9月30日星期五

Slide 5

Slide 5 text

Git was... • designed by Linus Torvalds (Linux creator) • for Linux kernel development • at 2005. 11年9月30日星期五

Slide 6

Slide 6 text

Why Git is better than X • http://zh-tw.whygitisbetterthanx.com/ • 便宜的本地分支 • 所有內容都在本地端 • Git很快 • Git很小 • Staging功能 • 分散式 • 適用任何工作流程 • GitHub rocks! 11年9月30日星期五

Slide 7

Slide 7 text

Projects using Git.. • Git • Linux Kernel • Perl • Gnome • Ruby on Rails • Debian • Eclipse • Android • X.org • KDE • Qt • PostgreSQL 11年9月30日星期五

Slide 8

Slide 8 text

git commit -m “perfect commit” 10 common cases before push... 11年9月30日星期五

Slide 9

Slide 9 text

Setup • 安裝Git • $ mkdir git_example • $ cd git_example • $ git init 11年9月30日星期五

Slide 10

Slide 10 text

case1:新增/修改 a.txt • $ touch a.txt • $ vim a.txt • $ git add a.txt • $ git commit -m “modified a.txt” 11年9月30日星期五

Slide 11

Slide 11 text

case2:修改 a.txt和b.txt • $ vim a.txt • $ vim b.txt • $ git add . • $ git commit -m “modified a.txt and b.txt” 11年9月30日星期五

Slide 12

Slide 12 text

stage (index) 菜籃 櫃檯 11年9月30日星期五

Slide 13

Slide 13 text

• git add a.txt 放到菜籃 • git commit -m “modified a.txt” 送到櫃台 11年9月30日星期五

Slide 14

Slide 14 text

$ git status git add file vim file git add file git commit 11年9月30日星期五

Slide 15

Slide 15 text

Case3:修改 a.txt和 b.txt,但只要commit a.txt • $ vim a.txt • $ vim b.txt • $ git add a.txt • $ git commit -m “modified a.txt only” 11年9月30日星期五

Slide 16

Slide 16 text

11年9月30日星期五

Slide 17

Slide 17 text

Case4:不小心編輯了a.txt, 在add之前想要取消修改 • $ vim a.txt • $ git checkout a.txt 11年9月30日星期五

Slide 18

Slide 18 text

Case5:不小心編輯了a.txt,在add之後、 commit之前想要取消修改或取消add • $ vim a.txt • $ git add a.txt • $ git reset a.txt //(取消add)結帳前從菜籃裡拿出來 • $ git checkout a.txt //(取消修改) 11年9月30日星期五

Slide 19

Slide 19 text

11年9月30日星期五

Slide 20

Slide 20 text

git commit -a The “git commit -a” command is a shortcut to a two-step process. 11年9月30日星期五

Slide 21

Slide 21 text

Case6:git commit -am • git commit -am = git commit -a + git commit -m • $ vim a.txt • $ vim b.txt • $ git commit -am “modify a.txt and b.txt” 11年9月30日星期五

Slide 22

Slide 22 text

Case7:a new file... If you create a new file named “new.txt”, edit it, and issue the “git commit -a” command, you will see something like: 新檔案要記得先add 11年9月30日星期五

Slide 23

Slide 23 text

remove files • (1)file system • (2)git • only (1):rm a.txt、按右鍵delete、... • only (2):git rm --cached a.txt • (1)+ (2):git rm a.txt 11年9月30日星期五

Slide 24

Slide 24 text

完整刪除檔案 • step1:刪除檔案系統的 • step2:刪除git的 • step3:commit 11年9月30日星期五

Slide 25

Slide 25 text

Case8:刪除不會再用 到的a.txt • 方法⼀一(step1+2, step3) • $ git rm a.txt • $ git commit -m “remove a.txt” 11年9月30日星期五

Slide 26

Slide 26 text

Case8:刪除不會再用 到的a.txt • 方法二(step1->step2+3) • $ rm a.txt • $ git commit -am “remove a.txt” 11年9月30日星期五

Slide 27

Slide 27 text

Case8:刪除不會再用到的a.txt • 方法三(step1->step2->step3) • $ rm a.txt //刪除file system的 • $ git rm --cached a.txt //刪除git的 • $ git commit -m “remove a.txt” 11年9月30日星期五

Slide 28

Slide 28 text

Case9:修改上次的commit (忘了add b.txt就commit) • $ vim a.txt • $ vim b.txt • $ git add a.txt • $ git commit -m “modified a.txt” • $ git add b.txt • $ git commit --amend -m“modified a.txt & b.txt” 11年9月30日星期五

Slide 29

Slide 29 text

11年9月30日星期五

Slide 30

Slide 30 text

Case10:修改上次的 commit message • $ vim a.txt • $ git add a.txt • $ git commit -m “modified b.txt” • $ git commit --amend -m “modified a.txt” 11年9月30日星期五

Slide 31

Slide 31 text

看commit log • $ git log 11年9月30日星期五

Slide 32

Slide 32 text

穿越時空 看某個版本(GitX) • 安裝GitX • 每⼀一個版本有unique SHA • git checkout (SHA) • $ git checkout b27c983d1809a08afa0155ce9965346d13422e1b 11年9月30日星期五

Slide 33

Slide 33 text

• 新增 a.txt • add • commit 11年9月30日星期五

Slide 34

Slide 34 text

• 編輯a.txt • add • commit 11年9月30日星期五

Slide 35

Slide 35 text

• 新增b.txt • add • commit 11年9月30日星期五

Slide 36

Slide 36 text

git checkout 版本號 11年9月30日星期五

Slide 37

Slide 37 text

git show 看該版本變化 git checkout 切換到該版本 11年9月30日星期五

Slide 38

Slide 38 text

comparing commit $ git diff • $ git diff (沒add的) • show you changes in the working directory that are not yet staged for the next commit • $ git diff --cached(有add的) • show you the difference between the index and your last commit • $ git diff HEAD(全部) • shows changes in the working directory since your last commit 11年9月30日星期五

Slide 39

Slide 39 text

修改a&b 然後git add a.txt git diff (only b) git diff --cached (only a) git diff HEAD (a & b) 11年9月30日星期五

Slide 40

Slide 40 text

references • Git • slideshare by ihower:Git and GitHub • Git Tutorial • "git commit -a" and "git add" • Comparing Commits - Git Diff • The Git Object Model (SHA) • Why Git is Better than X 11年9月30日星期五