git メモ

git メモ

Cheat Sheet


リモートリポジトリをローカルにコピーする


$ git clone https://github.com/nilab/samples.git

コードを修正し、ステージに上げる、コミットする、リモートリポジトリへ反映する


$ git diff
$ git add -u
$ git status
$ git commit -m "hoge comment"
$ git push origin master

ワークツリーの状態を見る


-現在の状況がわからなくなったときは git status を使う。どのファイルがインデックスに入っているか、どれがコミットに入るかなどの情報がわかる

$ git status

ワークツリーとインデックスの差分を表示する


$ git diff

インデックスとリポジトリの差分を表示する


$ git diff --cached

リモートリポジトリの更新をローカルに反映する


$ git pull origin master

ワークツリーでの修正を取り消す


$ git checkout -- ファイル名

リモートリポジトリのブランチのリストを表示する


$ git branch -r

新しいブランチを作る


$ git branch hoge_new_branch
$ git checkout -b hoge_new_branch

タグを打つ、リモートリポジトリへ反映する


$ git tag -a v1.0 -m 'my version 1.0'
$ git push origin v1.0

リモートリポジトリのブランチをローカルリポジトリに持ってくる


$ git checkout -b hoge_branch origin/hoge_branch

master にマージする前に master の最新をブランチに反映する (rebaseを使う場合)


$ git checkout hoge_branch
$ git rebase master
$ git push --force origin hoge_branch

過去のリビジョンへと巻き戻す


$ git reset --hard コミット名(SHA-1ハッシュ)

ブランチ名の変更


$ git branch -m old_branch_name new_branch_name

ブランチの複数の履歴を1つの履歴にまとめてマージ


$ git merge --squash hoge_branch

ローカルのブランチを削除する


git branch -d hoge_branch

まだ master にマージされていないブランチは開発中とみなされて -d だけで削除はできない。その場合に、強制的にブランチを削除するには -D を使う

git branch -D hoge_branch

リモートブランチを削除する


$ git push origin :hoge_branch

または

$ git push --delete origin hoge_branch

チェリーピック


$ git cherry-pick

-[ヅ] git cherry-pick で他のブランチから特定のコミットだけマージする (2013-12-27)
--http://www.nilab.info/z3/20131227_02_git_cherry_pick.html

差分の統計情報を表示する


$ git diff --stat

初期設定


$ git config --global user.name "Nick Labadie"

$ git config --global user.email "nilabinfo@example.org"

$ git config --list
user.name=Nick Labadie
user.email=nilabinfo@example.org

$ cat ~/.gitconfig
[user]
name = Nick Labadie
email = nilabinfo@example.org

資料


-[ヅ] はじめてのgitクライアント導入 (2011-03-21)
--http://www.nilab.info/z3/20110321_z01.html

-Git - Book (Pro Git book)
--http://git-scm.com/book/ja/

-サルでもわかるGit入門 〜バージョン管理を使いこなそう〜 | どこでもプロジェクト管理バックログ
--http://www.backlog.jp/git-guide/

-Git Cheat Sheet 日本語版 | textdrop
--http://www.textdrop.net/doc/git-cheat-sheet-ja/

-見えないチカラ: A successful Git branching model を翻訳しました
--http://keijinsonyaban.blogspot.jp/2010/10/successful-git-branching-model.html

-はてなブックマーク - NI-Lab.の電子栞 - git
--http://b.hatena.ne.jp/nilab/git/

-書籍: 入門Git: Book4798023809

-書籍: 入門git: Book427406767X_nyumon_git

-GitHub メモ: GitHub