$30 off During Our Annual Pro Sale. View Details »

Git ライフを快適にする知られざるコマンドたち

Git ライフを快適にする知られざるコマンドたち

Git 初心者〜中級者に向けて、目立たないけど便利なコマンドを紹介します。

Tomoki Aonuma

August 27, 2013
Tweet

More Decks by Tomoki Aonuma

Other Decks in Programming

Transcript

  1. (JUϥΠϑΛ \ͪΐͬͱ ΋ͬͱ ௒^ շదʹ͢Δ ஌ΒΕ͟ΔίϚϯυͨͪ !VBTJ

  2. VBTJ 

  3. w(JU)VC೥ੜ wͣͬͱ࢖ͬͯΔ wҰਓͰ࢖ͬͯΔ

  4. ͣͬͱҰਓͰ࢖ͬͯΔ

  5. $ git blame Document.h ca55733e (Tomoki Aonuma ... ad2d179e (Tomoki

    Aonuma ... 95074544 (Tomoki Aonuma ... c7bc39f9 (Tomoki Aonuma ... 95074544 (Tomoki Aonuma ... ca55733e (Tomoki Aonuma ... ^02e6c80 (Tomoki Aonuma ... a3a5d708 (Tomoki Aonuma ... fc79def1 (Tomoki Aonuma ...
  6. νʔϜͷ͜ͱ͸ ෼͔Βͳ͍ʜ

  7. ҰਓͰศརʹ ࢖͏ํ๏ ڭ͑·͢

  8. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˑˑˑ ˒˒˒

  9. git help

  10. •ࠔͬͨΒHELP •Α͘࢖͏ίϚϯυ΄ͲΑ͘มΘΔ •git help -a ←ίϚϯυҰཡ •git help -g ←ΨΠυҰཡ

    git help <cmd>
  11. wgit help config wgit help glossary w༻ޠू wgit help revisions

    wHEAD^ͱ͔dev..masterͱ͔ git help <cmd>
  12. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒ˑˑ ˒˒ˑ

  13. git status -sb

  14. git status -sb git status \ --short \ --branch

  15. git status $ git status # On branch master #

    Your branch is ahead of 'origin/mast # (use "git push" to publish your lo # # Untracked files: # (use "git add <file>..." to includ # # hoge nothing added to commit but untracked files present (use "git add" to track)
  16. git status -sb $ git status -sb ## master...origin/master [ahead

    1] ?? hoge
  17. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒ˑˑ ˒˒ˑ

  18. ls .git/hooks git help hooks

  19. ls .git/hooks git help hooks •৭ʑͳλΠϛϯάͰ૸ΔϑοΫ •ίϛοτલޙ •Ϧϕʔεલ •νΣοΫΞ΢τޙ…

  20. ls .git/hooks git help hooks •Kobito ͷ։ൃͰ͸ pre-commit ϑοΫͰ ιʔεϑΝΠϧ͕λʔήοτʹ

    ؚ·Ε͍ͯΔ͔νΣοΫ •gem ‘xcodeproj’
  21. ls .git/hooks git help hooks •Kobito ͷ։ൃͰ͸ pre-commit ϑοΫͰ ιʔεϑΝΠϧ͕λʔήοτʹ

    ؚ·Ε͍ͯΔ͔νΣοΫ •gem ‘xcodeproj’
  22. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒˒ˑ ˒˒ˑ

  23. git diff \ --patience

  24. git diff --patience •ʢͪΐͬͱʣݡ͍ diff •ࠩ෼͕ಡΈ΍͘͢ͳΔʢ͔΋ʣ

  25. ྫ void foo() { printf("foo\n"); } void foo() { printf("foo\n");

    printf("foo\n"); } void bar() { printf("bar\n"); } ฤूޙ ฤूલ
  26. git diff $ git diff a.c b.c ... @@ -1,4

    +1,9 @@ void foo() { printf("foo\n"); + printf("foo\n"); + +} +void bar() { + printf("bar\n"); }
  27. git diff --patience $ git diff --patience a.c b.c ...

    @@ -1,4 +1,9 @@ void foo() { printf("foo\n"); + printf("foo\n"); } + +void bar() { + printf("bar\n"); +}
  28. git diff --histogram •ʢ΋͏ͪΐͬͱʣݡ͍ diff •ࠩ෼͕ಡΈ΍͘͢ͳΔʢΑͶʁʣ

  29. git config \ diff.algorithm •git config \ diff.algorithm \ (patience|histogram)

    •;ͭ͏ͷ diff Λ࢖͏ͱ͖͸ git diff \ --diff-algorithm=default
  30. git config \ diff.algorithm •git log -U ΍ git format-patch

    ʹ΋Өڹ •࣮͸ͦΕΒͷίϚϯυʹ΋ --patience ͳͲΛࢦఆͰ͖Δ
  31. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒˒˒ ˒˒ˑ

  32. git diff git apply outside worktree ( )

  33. git diff •Git ϦϙδτϦͷ֎Ͱ΋࢖͑Δ •;ͭ͏ͷ diff ΑΓศར •git diff --binary

    •git diff --color •git diff --word-diff
  34. git diff •Git ϦϙδτϦͷதͰ ೚ҙͷ2ϑΝΠϧͷࠩ෼ΛऔΕΔ •git diff --no-index

  35. git apply •Git ϦϙδτϦͷ֎Ͱ΋࢖͑Δ •git diff ͷύονΛ ౰ͯΔͱ͖ʹ •git diff

    old new >patch git apply patch # old ͕ ফ͑Δʂ #(∵old+มߋ+վ໊==new)
  36. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒˒˒ ˒ˑˑ

  37. pushInsteadOf

  38. pushInsteadOf ͳ͠ # HTTPS URL ͰΫϩʔϯ $ git clone https://github.com/foo/bar

    # ... # ॻ͖ࠐΈݖݶΛ΋Βͬͨʂ $ git push origin master Username for 'https://github.com': # ໘౗ʂ
  39. pushInsteadOf $ cat ~/.gitconfig ... [url "git@github.com:"] " pushinsteadof =

    "git://github.com/" " pushinsteadof = "https://github.com/"
  40. pushInsteadOf ͋Γ # HTTPS URL ͰΫϩʔϯ $ git clone https://github.com/foo/bar

    # ... # ॻ͖ࠐΈݖݶΛ΋Βͬͨʂ $ git push origin master Total 0 (delta 0), reused 0 (delta 0) To git@github.com:foo/bar ...
  41. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒˒˒ ˒˒ˑ

  42. git new-workdir

  43. •ϦϙδτϦͷ࡞ۀσΟϨΫτϦΛ ৽ͨʹ࡞Δ •git new-workdir \ <repository> \ <new_workdir_path> \ [<branch>]

    git new-workdir
  44. •contrib σΟϨΫτϦʹ͋Δ •/usr/local/share/git- core/contrib/workdir ͋ͨΓ git new-workdir

  45. ஌ΒΕ͟Δ౓ ໾ཱͪ౓ ˒˒˒ ˒˒˒

  46. git rebase -i \ --autosquash

  47. --autosquash •ίϛοτϝοηʔδ͕ fixup! ͔ squash! Ͱ ࢝·ΔίϛοτΛࣗಈతʹ fixup/squash •fixup! ͷޙʹର৅ͷίϛοτͷ

    ϝοηʔδΛࢦఆʢ਺จࣈͰOKʣ
  48. --autosquash $ git log oneline a99e5d7 fixup! X d2cb153 fixup!

    A c85fc65 Add Foo $ git rebase -i --autosquash c85fc65^ pick c85fc65 Add Foo fixup d2cb153 fixup! A pick a99e5d7 fixup! X
  49. rebase.autosquash $ git config [--global] \ rebase.autosquash true ͍ͭͰ΋ autosquash

  50. None
  51. ஌Βͳ͍ίϚϯυ͸ ͋Γ·͔ͨ͠ʁ

  52. (JUʹ͸·ͩ·ͩ ίϚϯυ΍Φϓγϣϯ͕ ௥Ճ͞Ε͍ͯ·͢ ʢϦϦʔεϊʔτΛνΣοΫʂʣ

  53. ໘ന͍ίϚϯυΛ ݟ͚ͭͨΒ 2JJUBͰγΣΞʂ ʢએ఻Ͱ͢ʣ

  54. &OKPZ