基本的なコマンド
| コマンド |
概要 |
git add [filename] |
filenameを変更履歴へ追加する |
git restore [filename] |
filenameを変更前に戻す |
git status |
変更内容を確認する |
git commit -m "コメント" |
コメントを付けて、変更内容をコミットする |
git log |
変更履歴(コミットした履歴)を確認する |
リモートリポジトリの操作
| コマンド |
概要 |
git remote add origin [リモートリポジトリアドレス] |
リモートリポジトリを登録。originは名前。 |
git push origin master |
リモートリポジトリへアップロード。 |
git pull origin master |
リモートリポジトリからダウンロード。.gitディレクトリが存在する場所では、プルで。 |
git clone [リモートリポジトリ] |
リモートリポジトリをローカルに複製する。空のディレクトリにクローンする。.gitディレクトリが存在するディレクリでクローンしようとするとエラーが出る。 |
一般的な流れ
git pull origin master -- 他のメンバーがいれば、その変更内容をローカルへ取り込む。
git add . -- ローカルで何か作業をしたら、そのファイルを監視対象に加える。
git commit -m "[コメント]" -- 編集内容をコミット。
git push origin master -- リモートリポジトリへアップロード。
ブランチ
バグ改修、機能追加など作業ごとに分岐させて、ファイル編集を行う。競合(コンフリクト)が発生することがあるので、そのときは注意して編集すること。
| コマンド |
概要 |
git branch <branch name> |
<branch name>で分岐点を作る。 |
git branch |
分岐点の一覧表示。現在のブランチに"*"が付く。 |
git checkout <branch name> |
<branch name>へ切り替える。 |
git branch -d <branch name> |
<branch name>を削除する。 |
ブランチでの、作業の流れ
git branch issue -- バグ修正作業用に、issueブランチ作成。
git checkout issue
- myfile.txtを編集。修正内容をテストなど・・・修正完了。
git add myfile.txt
git commit -m "バグ修正"
git checkout master : -- 統合ブランチmasterへ切り替える。
git merge issue -- issueをmasterへ取り込む。
git branch -d issue -- issueブランチを残しておく必要がなければ、削除。
コンフリクトしたとき -- non fast-forward マージ --
git merge issueのとき、myfile.txtにて競合してマージ失敗。
myfile.txtを確認して、競合箇所を適宜編集。
git add myfile.txt
git commit -m "issueをマージ"
コンフリクトしたとき -- fast-forward マージ --
git checkout issue -- issueに切り替えておく
git rebase master
myfile.txtの競合エラーが表示されるので、適宜編集。
git add myfile.txt
git rebase --continue
- あらかじめ
rebaseで競合箇所を整理しておいて、first-forwardマージ可能な状態にする。
git checkout master
git marge issue