Gitでよくやることのソースを表示
←
Gitでよくやること
ナビゲーションに移動
検索に移動
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
=== リポジトリの作成 === <syntaxhighlight lang="bash"> $ mkdir <DIR> $ cd <DIR> $ git init --bare --shared </syntaxhighlight> === clone === ==== とりあえずclone ==== <syntaxhighlight lang="bash"> $ git clone <REPOSITORY_PATH> </syntaxhighlight> ==== ディレクトリ指定 ==== <syntaxhighlight lang="bash"> $ git clone <REPOSITORY_PATH> <DIR> </syntaxhighlight> === remote === ==== 一覧 ==== <syntaxhighlight lang="bash"> $ git remote </syntaxhighlight> ==== 追加 ==== <syntaxhighlight lang="bash"> $ git remote add <REMOTE_NAME> <REPOSITORY> </syntaxhighlight> ==== 削除 ==== <syntaxhighlight lang="bash"> $ git remote rm <REMOTE_NAME> </syntaxhighlight> ==== 名前変更 ==== <syntaxhighlight lang="bash"> $ git remote rename <OLOD_NAME> <NEW_NAME> </syntaxhighlight> === fetch === ==== とりあえずfetch ==== <syntaxhighlight lang="bash"> $ git fetch </syntaxhighlight> ==== remoteで削除されたブランチをローカルでも削除 ==== <syntaxhighlight lang="bash"> $ git fetch --prune </syntaxhighlight> === pull === ==== とりあえずpull ==== <syntaxhighlight lang="bash"> $ git pull </syntaxhighlight> ==== remoteで削除されたブランチをローカルでも削除 ==== <syntaxhighlight lang="bash"> $ git pull --prune </syntaxhighlight> ==== Git2.27.0以降でのwarning ==== <pre> hint: Pulling without specifying how to reconcile divergent branches is hint: discouraged. You can squelch this message by running one of the following hint: commands sometime before your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. </pre> ===== fetch + merge(デフォルト) ===== <syntaxhighlight lang="bash"> $ git config pull.rebase false </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git config --global pull.rebase false </syntaxhighlight> ===== fetch + rebase ===== <syntaxhighlight lang="bash"> $ git config pull.rebase true </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git config --global pull.rebase true </syntaxhighlight> ===== fast-forwardのみ ===== <syntaxhighlight lang="bash"> $ git config pull.ff only </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git config --global pull.ff only </syntaxhighlight> === 変更の確認 === <syntaxhighlight lang="bash"> $ git status </syntaxhighlight> === add === ==== とりあえず全部 ==== <syntaxhighlight lang="bash"> $ git add -A </syntaxhighlight> ==== 新規作成 or 変更されたもの ==== <syntaxhighlight lang="bash"> $ git add . </syntaxhighlight> ==== 変更があったもののみ ==== <syntaxhighlight lang="bash"> $ git add -u </syntaxhighlight> === commit === ==== とりあえずcommit ==== <syntaxhighlight lang="bash"> $ git commit </syntaxhighlight> ==== メッセージ付きでcommit ==== <syntaxhighlight lang="bash"> $ git commit -m "<MESSAGE>" </syntaxhighlight> ==== 無言でcommit ==== <syntaxhighlight lang="bash"> $ git commit --allow-empty-message -m "" </syntaxhighlight> ==== 空のcommit ==== <syntaxhighlight lang="bash"> $ git commit --allow-empty </syntaxhighlight> ==== commitの修正 ==== <syntaxhighlight lang="bash"> $ git commit --amend </syntaxhighlight> ==== dry run ==== <syntaxhighlight lang="bash"> $ git commit --dry-run </syntaxhighlight> === push === ==== とりあえずpush ==== <syntaxhighlight lang="bash"> $ git push </syntaxhighlight> ==== 別名でpush ==== <syntaxhighlight lang="bash"> $ git push origin <LOCAL_BRANCH>:<REMOTE_BRANCH> </syntaxhighlight> ==== dry run ==== <syntaxhighlight lang="bash"> $ git push --dry-run </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git push -n </syntaxhighlight> === merge === <syntaxhighlight lang="bash"> $ git merge <BRANCH_NAME> </syntaxhighlight> === branch確認 === <syntaxhighlight lang="bash"> $ git branch </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git branch -a </syntaxhighlight> === checkout === ==== 特定のコミットをcheckout ==== <syntaxhighlight lang="bash"> $ git checkout <COMMIT_ID> </syntaxhighlight> ==== ブランチ切り替え ==== <syntaxhighlight lang="bash"> $ git checkout <BRANCH_NAME> </syntaxhighlight> ==== 新しくブランチをremoteから持ってくる ==== <syntaxhighlight lang="bash"> $ git checkout -b <BRANCH_NAME> <REMOTE>/<BRANCH_NAME> </syntaxhighlight> e.g <syntaxhighlight lang="bash"> $ git checkout -b develop origin/develop </syntaxhighlight> ==== checkoutできないとき ==== エラー内容 <pre> fatal: git checkout: updating paths is incompatible with switching branches. Did you intend to checkout 'origin/remote-name' which can not be resolved as commit? </pre> こうする <syntaxhighlight lang="bash"> $ git remote show <REMOTE> $ git remote update $ git fetch $ git checkout -b <BRANCH_NAME> <REMOTE>/<BRANCH_NAME> </syntaxhighlight> === stash === ==== とりあえず面倒なとき ==== <syntaxhighlight lang="bash"> $ git stash </syntaxhighlight> ==== メッセージ付きでstash ==== <syntaxhighlight lang="bash"> $ git stash save "<MESSAGE>" </syntaxhighlight> ==== 一覧 ==== <syntaxhighlight lang="bash"> $ git stash list </syntaxhighlight> === log === ==== 1行表示 ==== <syntaxhighlight lang="bash"> $ git log --oneline </syntaxhighlight> ==== グラフィカル表示 ==== <syntaxhighlight lang="bash"> $ git log --graph </syntaxhighlight> ==== 追加/削除行数 ==== <syntaxhighlight lang="bash"> $ git log --numstat </syntaxhighlight> ==== 変更したファイル ==== <syntaxhighlight lang="bash"> $ git log --name-status </syntaxhighlight> ==== 絞り込み ==== ===== 期間(相対値) ===== <syntaxhighlight lang="bash"> $ git log --since="10 days ago" --until="2 days ago" </syntaxhighlight> ===== 期間(絶対値) ===== <syntaxhighlight lang="bash"> $ git log --since="2019/03/01" --until="2019/03/03" </syntaxhighlight> ===== 件数 ===== <syntaxhighlight lang="bash"> $ git log -1 </syntaxhighlight> ===== ファイル ===== <syntaxhighlight lang="bash"> $ git log ./dokokanoDIR/nanikanoFILE </syntaxhighlight> ===== 人 ===== <syntaxhighlight lang="bash"> $ git log --author='dareka' </syntaxhighlight> ===== コミットログ ===== <syntaxhighlight lang="bash"> $ git log --grep='コメント' </syntaxhighlight> ===== マージコミット ===== <syntaxhighlight lang="bash"> $ git log --merges </syntaxhighlight> ===== マージコミットを除く ===== <syntaxhighlight lang="bash"> $ git log --no-merges </syntaxhighlight> ==== format ==== <syntaxhighlight lang="bash"> $ git log --pretty=format:"[%ad] %h %an : %s" </syntaxhighlight> {| class="wikitable" !|パラメーター !|説明 |- |%H |コミットのハッシュ |- |%h |コミットのハッシュ (短縮版) |- |%T |ツリーのハッシュ |- |%t |ツリーのハッシュ (短縮版) |- |%P |親のハッシュ |- |%p |親のハッシュ (短縮版) |- |%an |Author の名前 |- |%ae |Author のメールアドレス |- |%ad |Author の日付 (-date= オプションに従った形式) |- |%ar |Author の相対日付 |- |%cn |Committer の名前 |- |%ce |Committer のメールアドレス |- |%cd |Committer の日付 |- |%cr |Committer の相対日付 |- |%s |件名 |} <syntaxhighlight lang="bash"> $ git log --oneline --decorate=full --graph --branches --tags --remotes --date=iso --format='%C(yellow)%H%C(reset) %C(magenta)[%ad]%C(reset) %C(cyan)@%an%C(reset) %C(auto)%d%C(reset) %s' </syntaxhighlight> === config関連 === ==== Author ==== <syntaxhighlight lang="bash"> $ git config --global user.name <NAME> $ git config --global user.email <EMAIL> </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git config user.name <NAME> $ git config user.email <EMAIL> </syntaxhighlight> ==== permission変更を無視 ==== <syntaxhighlight lang="bash"> $ git config core.filemode false </syntaxhighlight> ==== コメント入力をvimに変更 ==== <syntaxhighlight lang="bash"> $ git config --global core.editor vim </syntaxhighlight> or <syntaxhighlight lang="bash"> $ git config core.editor vim </syntaxhighlight> [[Category:Git]] [[Category:よくやること]]
Gitでよくやること
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
ページ
議論
日本語
表示
閲覧
ソースを閲覧
履歴表示
その他
検索
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報