こんにちは!
まったりのんびり、@vVv_kenshi_vVvです!
Gitの状態を綺麗にする
プラグインアップデートしたけど取り消したい時、あれこれいじったけどやっぱり取り消したい時
Bashname@pc eccube % git status
On branch develop
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .htaccess
modified: app/Plugin/VeriTrans4G/Controller/PaymentController.php
modified: app/Plugin/VeriTrans4G/EventListener/Vt4gEvent.php
modified: composer.json
modified: composer.lock
modified: vendor/composer/autoload_classmap.php
modified: vendor/composer/autoload_static.php
modified: vendor/composer/installed.json
Untracked files:
(use "git add <file>..." to include in what will be committed)
app/Plugin/VeriTrans4G/Common/
app/Plugin/VeriTrans4G/Resource/tgMdkPHP/tgMdk/Lib/tgMdkDto/RakutenReAuthorizeRequestDto.php
app/Plugin/VeriTrans4G/Resource/tgMdkPHP/tgMdk/Lib/tgMdkDto/RakutenReAuthorizeResponseDto.php
no changes added to commit (use "git add" and/or "git commit -a")
name@pc eccube %
・全ての変更の破棄:Changes not staged for commit
未追跡ファイル、ディレクトリの削除:Untracked files
コマンド実行後
Bashname@pc eccube % git status
On branch develop
nothing to commit, working tree clean
name@pc eccube %
ローカル環境のみ追跡除外したい
環境により設定が違う場合に、Gitの追跡から除外したい場合に使う
Bashgit update-index --skip-worktree .htaccess
Gitコマンド一覧
ついつい調べてしまう、忘れっぽいあなた(私)の為に捧げるw
記事です!
リセット系
取り消しやコミット履歴を綺麗にする際に、使用するコマンドを紹介
reset
・直前のコミットの取り消し
Bashgit reset --herd HEAD^
・直前のリセットの取り消し
Bashgit reset --hard ORIG_HEAD
・addファイルを破棄する(最後にコミットした状態へ戻す)
Bashgit checkout HEAD -- [ファイル名]
未追跡ファイルの削除
checkout
・変更の破棄(ファイルの削除ではない)
Bashgit checkout HEAD ファイル名
git checkout HEAD app/Customize/TestController.php
・指定ディレクトリは以下の破棄
Bashgit checkout HEAD ディレクトリ名
git checkout HEAD app/Plugin/Api/
・全ての変更の破棄
ログ関連
表示を見やすくするのに使用するコマンド(オプション)
log
・ファイル作成者の特定
Bashgit log --diff-filter=A -- <ファイルパス>
・GUI( SourceTree など)までは、見やすくはなりませんが、気持ち良くなります。
Bashgit log --oneline --graph --decorate
・マージ履歴
Bashgit log --oneline --merged
Checkout
developブランチへ移動
指定の作業ブランチへ移動
Bashgit checkout feature/XXX
作業ブランチを作成して移動
Bashgit checkout -b feature/XXX
Commit
直前のコミットメッセージ変更
Push
指定ブランチをリモートブランチへプッシュ
Bashgit push origin feature/XXX
安全な強制プッシュ
Bashgit push --force-with-lease origin feature/XXX
Rebase
直前の2コミットをまとめる
Rebase取消
再Rebase
Bashgit rebase --continue
developブランチを現在ブランチへRebaseする
Stash
現在状況を退避する
直近のStashを適用する
Branch関連
現在地のブランチ名変更
Bashgit branch -m feature/test01
別のブランチ名変更
Bashgit branch -m feature/test01 feature/test01_bk
・developブランチにマージ済みローカルブランチの削除:maser
Bashgit branch --merged develop | grep -vE '^\*|master$|develop$' | xargs git branch -d
・developブランチにマージ済みローカルブランチの削除:main
Bashgit branch --merged develop | grep -vE '^\*|main$|develop$' | xargs git branch -d