-
準備編
- git clone git@github.com:Iovesophy/git-training.git
- git config --local user.name
"<name>"
- git config --local user.email
"<email>"
-
現在参照しているブランチ名を変更
- git branch -m
<new_branch_name>
- git branch -m
-
新規ブランチを任意のブランチをベースにして作成
- git checkout -b
<new_branch_name>
<base_branch_name>
- git checkout -b
-
ブランチを強制的に変更(checkout)
- git checkout -f
<target_branch_name>
- git checkout -f
-
インデックスに記録されているファイルをインデックスから解除
- git restore --staged
<filename>
- git restore --staged
-
インデックスに記録されているファイルとリモートトラッキングブランチとの差分
- git diff --cached origin/
<branch_name>
- git diff --cached origin/
-
プルリクエストで発生したコンフリクトを修正
- mergeで解決
- git merge
<to_merge_branch_name>
- git add
<filename>
- git merge --continue
- git merge
- rebaseで解決
- git pull --rebase origin
<to_merge_branch_name>
- git add
<filename>
- git rebase --continue
- git pull --rebase origin
- pullで解決
- git pull origin
<to_merge_branch_name>
- git add
<filename>
- git merge --continue
- git pull origin
- mergeで解決
-
インデックスに記録されている変更を直前のコミットに混ぜる
- git commit --amend
-
前にいたブランチに戻る
- git checkout -
-
ファイルの行単位で最終変更がどのコミットで行われたのか確認
- git blame
<filename>
- git blame
-
直前のコミットで変更したファイルの内容を見る
- git show
-
コミット対象外のファイルを削除
- git clean -f
- option
- d: ディレクトリも含める
- f: 削除
- n: Dry-run
-
ワーキングツリーの変更を元に戻す
- git checkout .
-
ワーキングツリーとインデックスの変更を元に戻す
- git checkout -f
-
リベースをキャンセル
- git rebase --abort
-
cherry-pickをキャンセル
- git cherry-pick --abort
-
マージをキャンセル
- git merge --abort
-
特定のファイルをインデックスに追加
- git add
<filename>
- git add
-
HEADの状態をインデックスに戻す
- git reset --mixed HEAD^
-
ワーキングツリーとインデックスの状態をHEADに戻す
- git reset --hard HEAD
-
特定のファイルのブロックだけインデックスに追加
- git add -p
<filename>
- git add -p
-
ワーキングツリーとインデックスの差分をインデックスに追加
- git add -u
-
インデックスとHEADの差分を表示
- git diff --cached
-
強制的にプッシュ
- git push -f
<repository_name>
<branch_name>
- git push -f
-
リモートブランチの更新を取り込んで特定のブランチをベースにリベース
- git pull --rebase
<repository_name>
<branch_name>
- git pull --rebase
-
HEADのコミットメッセージを変更
- git commit --amend -m
"<message>"
- git rebase -i HEAD~
<number>
- r, reword
<commit>
= use commit, but edit the commit message
- r, reword
- git commit --amend -m
-
Gitの操作履歴を閲覧
- git reflog
-
前のブランチに強制的にチェックアウト
- git checkout - -f
-
ワーキングツリーとインデックスの変更を直前のコミットに混ぜる
- git commit -a --amend