Skip to content

Instantly share code, notes, and snippets.

@poutyface
Created December 29, 2010 17:37
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save poutyface/758790 to your computer and use it in GitHub Desktop.
Save poutyface/758790 to your computer and use it in GitHub Desktop.
gitの使い方
githubへ登録
===========
git remote add origin git@github.com:<username>/<application_name>.git
git push origin master
初期設定
=======
git config --global user.name "Foo Bar"
git config --global user.email "foo@bar.com"
git config --global color.ui auto
--globalオプションでホームディレクトリの.gitconfigへ書きだされる
リポジトリ初期化
==============
git init
./.git ディレクトリが作成される
基本設定の確認
============
git var GIT_COMMITTER_IDENT
git var GIT_AUTHOR_IDENT
最初のコミット
============
git add .
git commit -m "initial commit"
git diff
============
変更内容の確認
- 変更前の内容
+ 変更後の内容
git diff => git add していない変更点を出力
git diff HEAD => git commit していないすべての変更点を出力
git diff --cached => HEAD とインデックス(addしてる)との変更点のみを出力
git add
=======
git add [ファイル名]
git add -u => バージョン管理されているファイルを一括でaddする
git add -A => バージョン管理されていないファイル(新規ファイル)を一括でaddする
git add -p => 部分的にaddする時
git commit
==========
git commit -m "hogehoge"
git commit -a -m "hogehoge" => git commit -u, git commit -m を一括で
git commit -m "hogehoge" [ファイル名] => 指定したファイルのみをコミット
git commit --amend => コミットやりなおし
git status
==========
変更内容の要約
git show
========
コミットのログメッセージと変更内容が出力される
git reset
=========
git reset [ファイル名] => 次のコミットに含みたくないファイルを指定
git reset => すべてのaddしてきた物を指定したのと同じ
git reset HEAD^ => 最新のコミットを捨てる(一つ前のHEADに戻る)
git revert
===========
git revert [コミットオブジェクト] => 過去のコミットを打ち消す
git log
=======
変更履歴をみる
git log -<数字> => 出力するコミット数を制限
git checkout
=============
git checkout [PATH] => インデックスに記録されている状態に復帰
git checkout HEAD [PATH] => 最新のコミットに記録されたファイルに復帰
.gitignore
==========
.gitignoreファイルにバージョン管理の対象としないファイルを書く
バックアップ用リポジトリの作成
==========================
mkdir -p /repository/hoge.git
cd /repository/hoge.git
git --bare init => --bare ワークツリーなしでリポジトリを作成するという意味
ワークディレクトリにもどって
git push /repository/hoge.git master
git clone
=========
バックアップからコピーしてくる
git clone /repository/hoge.git hoge
git push
========
元のリポジトリにブランチをすべて転送
git push => git push origin master と同じ
git pull
========
origin から最新のコミットを取得
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment