Git: basic to advanced

22
Git: Basic to Advanced Yodalee <[email protected]>

Transcript of Git: basic to advanced

Page 1: Git: basic to advanced

Git: Basic to AdvancedYodalee <[email protected]>

Page 2: Git: basic to advanced

Before start某:小弟我想知道merge, cherry什麼的, rebase還有reflog某:可以的話 stash 順便

某:log --graph介紹一下

某:我只會commit嗚嗚

某:remote的概念可以介紹一下呀

某:我不會交女朋友呀(炸

(╯-_-)╯ ~╩╩ , man git-XXX (無誤)

Page 3: Git: basic to advanced

Git: Basic

git initgit addgit commit

Extend Reading Material:http://johnjohnlys.blogspot.tw/2012/08/git-part-1.html

Page 4: Git: basic to advanced

Git Basic

Page 5: Git: basic to advanced

Git: Reference

➔ git branch➔ git tag➔ HEAD, ORIG_HEAD, FETCH_HEAD

Notice:1. Each reference points to a commit (Hash)2. Low cost to move a reference (FF)

Page 6: Git: basic to advanced

Git: Reference

Page 7: Git: basic to advanced

Git: Remote

● Remote and Local are independent.

● Use fetch/push to get/set remote data.

Page 8: Git: basic to advanced

Git rebase

Cut down a branch, connect to otherSteps:1. Checkout the new-base2. Re-apply commits3. Stop if conflict

Page 9: Git: basic to advanced

Git rebase -i

Interactive Rebase, you can:● Change content(edit)● Change message(reword)● Change order● Combine/Split commit(squash, reset)● Run command(exec)

Extend Reading Material:http://blog.yorkxin.org/posts/2011/07/29/git-rebase/

Page 10: Git: basic to advanced

Git rebase

!rebase 有機會竄改歷史!

在已經merge 的branch 上rebase 會怎麼樣?➔ = = 建議千萬別這樣做..上次有人這樣 結果把分枝弄得一團亂..➔ 樓上..然後呢@@➔ 就把分枝弄得一團亂 很不方便..

Page 11: Git: basic to advanced

git stash

● Temporary store the changes you made.● Useful with rebaseBasic usage: stash <push, pop, list>

Extend Reading Material:http://yodalee.blogspot.tw/2013/12/git-stash.html

Page 12: Git: basic to advanced

git format-patch, am

● git format-patch <Ref>○ generate patches

● git am <path-to-patch>○ Apply patches

Page 13: Git: basic to advanced

git bisect

Find the commit that changes somthing, steps:1. bisect start2. Set “bisect bad”, “bisect good”3. Keep testing; set bad or good4. Find the commit

Extend Reading Material:http://yodalee.blogspot.tw/2014/08/git-bisect.html

Page 14: Git: basic to advanced

git cherry-pick

Pick out the change in some commit.● -n, --no-commit: allow you edit, commit

manually

Not very useful, actually.

Page 15: Git: basic to advanced

Git inside

ls * in .git:● Object/: Data● Refs/: Reference● Logs/: Change to Reference● other files

Extend Reading Material:http://git-scm.com/docs/gitrepository-layout

Page 16: Git: basic to advanced

Git reflog● View the list of HEAD movement. record the

Hash and action● Log when you move reference by

<commit, rebase, reset, checkout>

If you get the Hash, you can recover it.

Page 17: Git: basic to advanced

Git fsck

● Fsck check repository integrity, find dangling commits.

● Even reflog is deleted or not record, ex:git branch -D some-branchrm -Rf .git/logs/

Page 18: Git: basic to advanced

Git gc● Git do 'git gc --auto' automatically, it will

○ Pack the loose files (refs->packed-refs)○ Delete the Non-reference files.

Page 19: Git: basic to advanced

Git filter-branch

Filter out some commits, and do some change.ex. git filter-branch --msg-filter “echo XD” branch--Change all commit message into “XD”ex. git filter-branch --index-filter “rm xxx” branch--Delete file from git repository

Extend Reading Material:http://yodalee.blogspot.tw/2014/06/git-gc.html

Page 20: Git: basic to advanced

Git filter-branch

!filter-branch 就是要更動歷史!

在已經merge 的branch 上filter-branch會怎麼樣?➔ = = 建議千萬別這樣做..上次有人這樣 結果把分枝弄得一團亂..➔ 樓上..然後呢@@➔ 就把分枝弄得一團亂 很不方便..

Page 21: Git: basic to advanced

Git useful tool

Linux: gitk, gitghttps://wiki.gnome.org/Apps/Gitg/

MacOS: http://gitx.frim.nl/

Windows: X! I don’t know

Page 22: Git: basic to advanced

The End

● Git is POWERFUL. With basic skills, it can fulfill daily requirement.

● Hope everyone can become Git Master