Last active
October 14, 2020 01:17
-
-
Save ponsuke0531/6adae39f95d14080bdc94f94b342b96c to your computer and use it in GitHub Desktop.
Gitでやりたいことをやりたい時に参考にするサイト集 ref: https://qiita.com/ponsuke0531/items/f13e657a28a0d84a5e31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ディレクトリ名を指定してクローン | |
$ git clone {url} {ディレクトリ名} | |
# ブランチを指定してクローン | |
$ git clone -b {ブランチ名} {url} | |
# フェッチ | |
$ git fetch origin | |
# フェッチ : 削除されたリモートブランチをoriginから削除 | |
$ git fetch --prune | |
# フェッチ : 全ブランチを更新して削除されたブランチもoriginから削除 | |
$ git fetch --all --prune | |
# プル | |
$ git pull origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ブランチを作ってプッシュしたい | |
$ git checkout -b {ブランチ名} | |
$ git push origin {ブランチ名} | |
# ブランチを確認したい(ローカル) | |
$ git branch | |
# ブランチを確認したい(リモート) | |
$ git branch -r | |
# ブランチ名を変更したい(ローカルブランチ名を変更 > リモートブランチ削除 > ローカルブランチPush) | |
$ git branch -m {旧ブランチ名} {新ブランチ名} | |
$ git push origin :{旧ブランチ名} | |
$ git push origin {新ブランチ名} | |
# 今のブランチを確認したい | |
git branch --contains=HEAD | |
# ユーザー名とメールアドレスを指定してコミットしたい | |
$ git -c user.name='ユーザー名' -c user.email='メールアドレス' commit -m 'コミットコメント' | |
# シンプルに(-s --short)まだコミットしていないものを見たい | |
$ git status -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ブランチを削除したい(普通) | |
$ git branch -d {branch名} | |
# ブランチを削除したい(強制) | |
$ git branch -D {branch名} | |
# ブランチを削除したい(リモート) | |
$ git push -d origin {ブランチ名} | |
# 特定のファイルだけ戻したい | |
$ git checkout {コミットのハッシュ値} {ファイルパス} | |
# ローカルの変更をなかったことにしたい(全部) | |
$ git reset --hard HEAD | |
# ローカルの変更をなかったことにしたい(特定ファイル) | |
$ git checkout {ファイル名} | |
# 直前のコミットを取り消したい | |
$ git reset --soft HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ディレクトリ名 | |
$ git mv {古いディレクトリ名} {新しいディレクトリ名} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# マージだけみたい | |
$ git log --merges | |
# 直近マージされたファイル名を見たい | |
$ git log -m -1 --name-status | |
# マージ以外だけみたい | |
$ git log --no-merges | |
# マージ元を非表示 | |
$ git log --first-parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# コミットのハッシュ値全部見る | |
$ git rev-list --all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ブランチを削除したい(普通) | |
$ git branch -d {branch名} | |
# ブランチを削除したい(強制) | |
$ git branch -D {branch名} | |
# ブランチを削除したい(リモート) | |
$ git push -d origin {ブランチ名} | |
# 特定のファイルだけ戻したい | |
$ git checkout {コミットのハッシュ値} {ファイルパス} | |
# ローカルの変更をなかったことにしたい(全部) | |
$ git reset --hard HEAD | |
# ローカルの変更をなかったことにしたい(特定ファイル) | |
$ git checkout {ファイル名} | |
# 直前のコミットを取り消したい | |
$ git reset --soft HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ディレクトリ名 | |
$ git mv {古いディレクトリ名} {新しいディレクトリ名} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// stashの一覧を確認したい | |
$ git stash list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 既存タグの確認(コメントを添えて) | |
$ git tag -n | |
# 既存タグの確認(リモートの) | |
$ git ls-remote --tags | |
# 軽量タグを打ってPush | |
$ git tag {タグの名前} | |
$ git push origin {タグの名前} | |
注釈をエディタで書いてタグを打つ | |
$ git tag -a {タグの名前} | |
注釈も書いてタグを打つ | |
$ git tag -am {注釈の内容} {タグの名前} | |
タグを削除してPush | |
$ git tag -d {タグの名前} | |
$ git push origin :{タグの名前} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 特定のコミットとコミットの間を全部チェリーピック | |
$ git cherry-pick {特定のコミットのハッシュ1}..{特定のコミットのハッシュ2} | |
# マージのコミットをチェリーピック | |
$ git cherry-pick -m 1 {MergeのCommitのハッシュ} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HEADのハッシュを見たい | |
$ git rev-parse HEAD | |
# ハッシュ値が含まれているブランチをリモートのブランチからリストアップする | |
$ git branch -r --contains {ハッシュ値} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ローカルの変更を確認したい | |
$ git diff HEAD | |
# ブランチで差分 | |
$ git diff {ブランチA} {ブランチ名} | |
# コミットのハッシュで差分 | |
$ git diff --stat --name-only {コミットA} {コミットB} | |
# タグで差分 | |
$ git diff --name-only {old tag name} {new tag name} | |
# 特定ファイルの差分 | |
$ git diff {old tag name} {new tag name} {特定ファイル} | |
# 特定フォルダ配下の差分 | |
$ git diff --name-only {old tag name} {new tag name} {特定ディレクトリ} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git log [オプション] | |
# 変更したファイル名を見たい | |
$ git log --name-only {(必要なら)ハッシュ} | |
# 履歴を見る(タグ情報添え) | |
$ git log --decorate | |
# 履歴を見る(Diff添え) | |
$ git log -p | |
# 履歴を見る(ファイル指定) | |
$ git log -p {ファイルパス} | |
# {x}個分コミットの履歴を見る | |
$ git -p -{x} --{fileNameへのパス} | |
# ハッシュだけみたい(コメントを添えて) | |
$ git log --pretty=oneline | |
# ハッシュだけみたい(本当にハッシュだけ) | |
$ git log --pretty=oneline | awk '{print $1}' | |
# 特定日以降だけみたい | |
$ git log --after='2017-08-10 00:00:00' | |
# オプションを忘れたので確認したい | |
$ git log -help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# マージだけみたい | |
$ git log --merges | |
# 直近マージされたファイル名を見たい | |
$ git log -m -1 --name-status | |
# マージ以外だけみたい | |
$ git log --no-merges | |
# マージ元を非表示 | |
$ git log --first-parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# コミットのハッシュ値全部見る | |
$ git rev-list --all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--name-only | |
: 変更のあったファイル名のみ表示する. | |
-w | |
: 改行コードの変更を除く | |
--ignore-all-space | |
Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none. | |
--ignore-blank-lines | |
Ignore changes whose lines are all blank. | |
--inter-hunk-context=<lines> | |
Show the context between diff hunks, up to the specified number of lines, thereby fusing hunks that are close to each other. Defaults to diff.interHunkContext or 0 if the config option is unset. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git config --global core.autoCRLF false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HEADのハッシュを見たい | |
$ git rev-parse HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ブランチを作ってプッシュしたい | |
$ git checkout -b {ブランチ名} | |
$ git push origin {ブランチ名} | |
# ブランチを確認したい(ローカル) | |
$ git branch | |
# ブランチを確認したい(リモート) | |
$ git branch -r | |
# ブランチ名を変更したい(ローカルブランチ名を変更 > リモートブランチ削除 > ローカルブランチPush) | |
$ git branch -m {旧ブランチ名} {新ブランチ名} | |
$ git push origin :{旧ブランチ名} | |
$ git push origin {新ブランチ名} | |
# 今のブランチを確認したい | |
git branch --contains=HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[push] | |
default = current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[core] | |
autoCRLF = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment