gitコマンドのメモ
自分用 適当に追記
Clone
git clone https://github.com/napoporitataso/piyopiyo.gitgit clone https://github.com/napoporitataso/piyopiyo.git fooリモートの変更を取り込む
git fetch origin master
git merge origin/master
# または
git pull origin masterorigin/ブランチ名 っていうのは、ローカルに存在する、リモートと同じものが保持されてるブランチの名前。
git fetch は、指定したリモートブランチからローカルの origin/ブランチ名 ブランチに、最新の状態を持ってくる。
git merge は、指定したブランチを現在の作業ブランチにマージする。
マージを取り消す
conflictした時、とりあえず元に戻せる
git merge --abort全てのリモートブランチをfetch
未知のブランチも取れる
git fetch --all変更したファイルを表示
git statusOn branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: path/to/staged/file.js
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: path/to/not/staged/file_1.js
modified: path/to/not/staged/file_2.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
path/to/nntracked/file.jsChanges to be committed…git add済みの変更ファイルChanges not staged for commit…git addしてない変更ファイルUntracked files… インデックスされてない (まだGitの管理下に無い) ファイル
コミットしていないファイルの変更を元に戻す
git checkout path/to/filegit checkout .コンフリクトした時
git checkout --theirs path/to/file
git add path/to/filegit checkout --ours path/to/file
git add path/to/filegit reset --hard origin/masterインデックスに追加
コミット対象にするということ。新規のファイル、変更したファイル、削除したファイル、どれもインデックスに追加する必要がある。
git add path/to/filegit add .git add *.jsgit add --updategit add --allインデックスへの追加や削除を取り消す
git resetコミット
git commit --message <message>コミットを取り消す
HEAD^ はHEADの一つ前を表す
git reset --soft HEAD^git reset --mixed HEAD^git reset --hard HEAD^git update-ref -d HEADプッシュ
git push origin mastergit push origin --allgit push --set-upstream origin mastergit push origin master --force一旦バージョン管理されたものを管理外にする
git rm --cached path/to/file
git rm --cached *.abcgit rm --cached -r path/to/dirgit rm path/to/filegit rm --dry-run -r path/to/dirgit rm --ignore-unmatch -r path/to/dirfatal: pathspec 'xxx' did not match any filesリモートブランチを全て表示
git branch -rローカルブランチを全て表示
git branchローカルブランチを作る
git branch <branchname>git checkout -b <branchname>現在のブランチを切り替える
git checkout <branchname>リモートブランチをチェックアウトする
git checkout -t <remotebranchname>git checkout -b <localbranchname> <remotebranchname>リモートブランチを削除する
git push --delete origin <remotebranchname>歴史から抹消する
※危険、要バックアップ
filter-branch の --index-filter に渡したコマンドを全てのコミットに対して実行し、インデックスを書き換える。よって rm コマンドを指定すると、歴史からファイルを抹消できる。
--prune-empty をつけると、ファイルが抹消された結果としてカラになってしまったコミットを自動で消せる。
完了後は要強制プッシュ。また、他のメンバーには再Cloneしてもらった方がいいらしい。
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch path/to/file" --prune-empty -- --allgit filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch path/to/file path/to/dir/*" --prune-empty -- --allログを見る
長すぎてページめくりが発生した場合、終了するには q を入力
git loggit log -5git log --statgit log --pretty=format:"[%ad] %h %an %s" --date=isodiffを見る
git diff -- path/to/filegit diff <特定のコミットのSHA> -- path/to/filegit diff -w -- path/to/fileガベージコレクション
git gc設定
git config --listgit config --global user.name napoporitataso
git config --global user.email napoporitataso@example.comgit config --global core.autoCRLF falsegit config --global --unset <name>git config --global credential.helper store参考にさせていただいた記事
git fetch コマンドでリモートリポジトリの内容をローカルリポジトリに取り込む方法
【初心者向け】git fetch、git merge、git pullの違いについて - Qiita
git add -u と git add -A と git add . の違い | note.nkmk.me
Git の Reset, Checkout, Revert の違い - yu8mada
git config --global で設定した値を削除する方法 - Qiita
忘れやすい人のための git diff チートシート - Qiita
Gitリポジトリをメンテナンスして軽量化する - Qiita
git filter-branchで過去の全てのcommitから画像ファイルの追加/変更をなかったことにしてリポジトリを軽量化する - dskd
キリウ君が読まないノート