Gitのお勉強
公式DOCS
Gitの構成
Gitの設定
git config --global user.name "robo nchu" git config --global user.email "robonchu@gmail.com" git config --global color.ui true
ヘルプ:git config --help
はじめてのGit
git init git add <file> git commit <file> addとcommitをまとめて実行:git commit -am "" git log ワンラインで表示:git log --oneline 変更点を表示:git log -p どのファイルに変更が加えられたか:git log --stat git status 変更分を消す:git checkout -- <file> 変更分の確認:git diff ステージングエリア上のdiff:git diff --cached すべてadd:git add . 削除:git rm <file> 移動:git mv <file> 上げたくないファイルがあるとき:.gitignoreファイルを作り、*.logなどを記入。おいた場所の下位すべてに適応される。 git commit -m "message" 直前のコミットの変更:git commit --amend 直前のコミットを取り消す:git reset --hard HEAD ひとつまえまでのコミットを取り消す:git reset --hard HEAD^ ひとつ前に消したコミットを取り戻す:git reset --hard ORIG_HEAD git branch hoge git checkout hoge masterにhogeを統合:git checkout master -> git merge hoge branchの削除:git branch -d hoge git checkout -b hogehoge
コンフリクトの解決
コンフリクトが起きたファイルを開く
>>> or <<< のどちらかを消すor修正する
add
commit
tag
commit jankfdjbnkdlnbk~ のcommit idに名前をつける
直前のコメットにtagをつける:git tag v1.0 git tag -> v1.0 tagをつけたcommitを見る:git show v1.0 任意のコミットにtagをつける:git tag v0.9 jankfdjbnkdlnbk tagの消し方:git tag -d v0.9
aliasの設定
git config --global alias.co checkout git config --global alias.st status -> git st 設定を見る:git config -l
共有レポジトリの作成
共有レポジトリ:share_robot.git cd share_robot.git git init --bare cd ./../my_robot git remote add origin ./../share_robot.git/ git config -l > core.repositoryformatversion=0 > core.filemode=true > core.bare=false > core.logallrefupdates=true > remote.origin.url=./../share_robot.git/ > remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* リモート消すとき:git remote rm origin origin(share)にpushするとき:git push origin master clone: git clone ./share_robot.git/ my_robot2 cd my_robot2 modify something git add . git commit -m "modify something" git push origin master cd ./../my_robot git pull origin master そうするとmy_robot2での変更がmy_robotで反映されていることが確認できる
stash
変更を一時的に退避
一時退避:git stash save 退避した内容確認:git stash list -p 退避した作業を復元:git stash pop
Stash | 逆引きGit | サルでもわかるGit入門 〜バージョン管理を使いこなそう〜 | どこでもプロジェクト管理バックログ
cherry-pick & rebase
わかりやすすぎる👇
初心者でもわかる!リベースの使い方を解説します | Git編:一歩踏み出すフロントエンド入門
ex:
rebase -i HEAD~~
参考
初心者でもほぼ無料でGitの使い方を学べるコンテンツ7選 - paiza開発日誌
Git 学習コース Ⅰ | プログラミングの入門なら基礎から学べるProgate[プロゲート]