恐らくcommit
と合わせてかなりお世話になるであろうコマンド…
はじめに
基本の流れ
凡例
記号 | 意味 | 使い方 |
---|---|---|
$ |
「"コマンドライン"で使えるコマンド」のしるし。 通常、Gitを始めとする「シェルスクリプト」系の説明では、コマンドの文頭に $ をつけて表現されることが多いようです。当ブログでもそれに倣って記載してます。 |
実際にコマンドを入力するときは、git~ 以下をコピペしてください。 |
# |
コメント | 補足事項など。 (対話モードでは使えません、、、) |
<> |
編集点(という表現で良いのかな…?) | 任意の名前、識別子を入力してください。 |
ステージする(コミット予定に追加)
管理対象にあるファイルをすべて追加
$ git add -A
$ git add --all
ファイル名やディレクトリを指定して追加
$ git add <ファイル名>
$ git add <ディレクトリ>
現在のディレクトリの変更をすべて追加
$ git add .
ステージから下ろす
インデックスから除外
該当のディレクトリ内でファイルを削除した場合など。
$ git rm -r <ファイル名>
ステージされたファイルを確認
ステージに不足が無いか確認
$ git status
【例】何も上げてない場合
# 入力 $ git status # 結果 On branch master Your branch is up to date with 'origin/master'. Last commands done (4 commands done): pick 2757f4b fix directory hierarchy. pick 467d0e2 fix directory hierarchy. (see more in file .git/rebase-merge/done) No commands remaining. You are currently editing a commit while rebasing branch 'master' on 'f71eb8a'. (use "git commit --amend" to amend the current commit) (use "git rebase --continue" once you are satisfied with your changes) nothing to commit, working tree clean
コミット予定ナシ、作業ツリーも空です。
【例】.gitignore
とREADME.txt
を修正して、.gitignore
はステージ済みの場合
On branch master Your branch is up to date with 'origin/master'. Last commands done (4 commands done): pick 2757f4b fix directory hierarchy. pick 467d0e2 fix directory hierarchy. (see more in file .git/rebase-merge/done) No commands remaining. You are currently editing a commit while rebasing branch 'master' on 'f71eb8a'. (use "git commit --amend" to amend the current commit) (use "git rebase --continue" once you are satisfied with your changes) Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: .gitignore Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md
コミット予定の変更履歴:
(ステージから下ろす場合はgit reset HEAD <file>...
してください)
変更あり:.gitignore
ステージされていない変更履歴:
(コミットする場合は、git add <file>...
してください。)
(作業中ディレクトリの変更をコミットから除外する場合は、git checkout -- <file>...
してください)
変更あり:README.md
変更をステージしつつ、ステージの一覧を表示
$ git add -v .
$ git add --verbose .
【例】何も上げてない場合
# 入力 $ git add -v . # 結果 Nothing specified, nothing added. Maybe you wanted to say 'git add .'?
何も指定されてないよ、コマンド間違えてない?
【例】.gitignore
とREADME.txt
を修正して、.gitignore
はステージ済みの場合
# 入力 $ git add -v . # 結果 add 'README.md'
追加 'README.md'
先にステージしているファイルは出力してもらえないみたいです。
それならgit status
を使おうかな、結果は長くなっちゃうけど。