Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

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

Tomoki Aonuma

August 27, 2013
Tweet

More Decks by Tomoki Aonuma

Other Decks in Programming

Transcript

  1. $ 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 ...
  2. 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)
  3. ྫ void foo() { printf("foo\n"); } void foo() { printf("foo\n");

    printf("foo\n"); } void bar() { printf("bar\n"); } ฤूޙ ฤूલ
  4. 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"); }
  5. 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"); +}
  6. git config \ diff.algorithm •git config \ diff.algorithm \ (patience|histogram)

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

    ʹ΋Өڹ •࣮͸ͦΕΒͷίϚϯυʹ΋ --patience ͳͲΛࢦఆͰ͖Δ
  8. git apply •Git ϦϙδτϦͷ֎Ͱ΋࢖͑Δ •git diff ͷύονΛ ౰ͯΔͱ͖ʹ •git diff

    old new >patch git apply patch # old ͕ ফ͑Δʂ #(∵old+มߋ+վ໊==new)
  9. pushInsteadOf ͳ͠ # HTTPS URL ͰΫϩʔϯ $ git clone https://github.com/foo/bar

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

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

    # ... # ॻ͖ࠐΈݖݶΛ΋Βͬͨʂ $ git push origin master Total 0 (delta 0), reused 0 (delta 0) To [email protected]:foo/bar ...
  12. --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