git-tipsが本家です。
English | 中文 | Русский | 한국어 | Tiếng Việt
git-tip -以下に紹介するtipsを実際に試すことができるCLIツールです。 (Here in Docker container)
tipsを追加したい場合はcontributing.mdを確認してください。
P.S: git version 2.7.4 (Apple Git-66)で動作検証をしています。
- GIT公式の基本的なコマンドのサンプルを表示する
- GIT公式のヘルプを表示する
- コミットメッセージからコミットを検索する
- リモートブランチと同期してローカルの変更を上書きする
- 特定のコミット時点で管理されている全ファイルを表示する
- ファーストコミットを取り消す
- 全てのコンフリクトしているファイルを表示する
- 特定のコミットで変更されたファイルを表示する
- 最終コミットからステージングされていない変更を表示する
- コミット対象のステージングされている変更を表示する
- ステージングされている変更とされていない変更の両方を表示する
- masterにマージ済みのブランチを表示する
- 前にいたブランチに素早く移動する
- masterにマージ済みのブランチを削除する
- 全てのブランチとその親ブランチを最新のコミットと共に表示する
- どのリモートブランチを追跡するか選択する
- ローカルブランチを削除する
- リモートブランチを削除する
- ローカルタグを削除する
- リモートタグを削除する
- ローカルで変更したファイルをHEADまで戻す
- 正反対のコミットを作ることで、元のコミットを取り消す
- コミットを破棄する。ローカルブランチのみで行うことを推奨
- 直前のコミットのコメントを変更する
- 現在のブランチのコミット履歴を表示する
- 直前のコミットの実行者を変更する
- 直前のコミットの実行者をデフォルト値にリセットする
- リモートブランチのURLを変更する
- 現在設定されている全てのリモートブランチを表示する
- ローカルとリモートの全部ランチを表示する
- リモートのブランチを表示する
- ファイル全体ではなく、ファイル中の一部変更点だけをステージングする
- GITの補完機能をインストールする
- 直近2週間の変更点を表示する
- masterからforkした時点よりあとのコミット履歴を表示
- コミットを別のブランチにcherry-pickする
- 特定のコミットが含まれているブランチを表示する
- エイリアスを作成する
- 前回コミットからの変更を一時保存する
- 前回コミットからの変更のうち、ステージングされていない変更を一時保存する
- 前回コミットからの変更をGit管理されていないファイルの変更も含めて一時保存する
- 前回コミットからの変更を名前をつけて一時保存する
- 前回コミットからの変更を全て一時保存する(ignoredしている、Git管理されていない、Git管理されている)
- 現在保存されているstashを表示する
- stashリストから削除せずに変更を適用する
- 最後のstashを適用し、適用したstashは削除する
- stashを全て削除する
- stashから1ファイルだけ取り出す
- Git管理しているファイルを全て表示する
- Git管理していないファイルを全て表示する
- Gitignoreで無視しているファイルを全て表示する
- リポジトリーからワーキングツリーを作成する(Git2.5)
- HEADからワーキングツリーを作成する
- ファイルをGit管理下から外す。ファイルは削除しない
- Git管理していないファイル/ディレクトリを削除する前に、ドライランで削除される対象を表示する
- Git管理していないファイルを強制削除する
- Git管理していないディレクトリーを強制削除する
- 全てのサブモジュールをアップデートする
- 現在のブランチでmasterにマージされていないコミットを表示する
- ブランチ名を変更する
- featureブランチをmasterにrebaseして、その後masterにマージする
- masterブランチをアーカイブする
- 前回のコミットをメッセージを除いて変更する
- リモートブランチで削除されているブランチへの参照を取り除く
- 一番最初のコミットのハッシュを取得する
- バージョンツリーを描画する
- reflogsから参照されているコミットを含めてバージョンツリーを描画する
- 指定したサブツリーだけをoriginにpushする
- サブツリーを現在のリポジトリに追加する
- 指定したサブツリーだけをpullする
- 指定したブランチをファイルに出力する
- バンドルからインポートする
- 現在のブランチ名を表示する
- コミット時に特定の1ファイルだけ無視する (e.g. Changelog)
- rebaseする前にstashする
- プルリクエストをID指定でローカルブランチにfetchする
- 現在のブランチの一番直近のタグを表示する
- 単語単位のdiffを表示する
- 一般的なdiffツールで変更を表示する
- Git管理しているファイルの変更を無視する
- assume-unchangedを無効にする
- .gitignoreに記載があるファイルを削除する
- 削除したファイルを元に戻す
- 特定のコミットハッシュまでファイルを戻す
- pullしたときにmergeではなくrebaseするよう変更する
- 全てのコンフィグとエイリアスの一覧を表示する
- ファイル名の大文字小文字変更を検知するように変更する
- カスタムエディターを追加する
- 誤字を自動修正する
- 指定のハッシュが、どのブランチにいるかを表示する
- ドライラン(ドライランをサポートしているコマンドに対して実行できる)
- コミットを前回のコミットの修正としてマークする
- rebase時に上記のコミット順を隣に並べ替えてわかりやすくする
- 指定したファイルだけコミットする
- インタラクティブにステージングする
- Gitが無視しているファイルを表示する
- Gitが無視しているファイルのステータスを表示する
- Branch1には入っていて、Branch2に入っていないコミットを表示する
- 直近n個のコミットログを表示する
- コンフリクトの解決法を記録してお、今後同じ理由でのコンフリクトが見つかったら同じ方法で自動的に解決する
- コンフリクトしたファイルをエディタで開く
- 現在のプロジェクトが使用しているオブジェクト数とディスク使用量を表示する
- 到達不能オブジェクトを削除する
- 作業リポジトリを gitwebで一時的にブラウジングする
- コミットログで署名も表示する
- グローバル設定を削除する
- 履歴を持たない新しい空ブランチを作成する
- 別ブランチのファイルを表示する
- ルートとマージコミットのみ表示する
- 直前の2コミットをインタラクティブにrebaseする
- 作業中のブランチを表示する
- 二分探索でバグの発生元を発見する
- pre-commitフックが仕掛けられているときに、チェックをスルーしてコミットする
- 特定のファイルの変更履歴を表示する (リネームされていても)
- 特定のブランチをクローンする
- 新しいブランチを作って移動する
- コミット時にファイルモードの変更を無視する
- ターミナルの出力に色を付けない
- ターミナルの出力の色設定を個別に変更する
- ローカルブランチを新しい順に表示する
- 文字列か正規表現でGit管理下のファイルの行を検索する
- 最新のリポジトリだけcloneする
- 指定の文字で全てのブランチのコミットログを検索する
- masterから指定のブランチに向けての最初のコミットを表示する
- ステージングしたファイルをステージングする前に戻す
- リモートリポジトリに強制的にpushする
- リモートリポジトリを追加する
- ファイルの全行に対して、最終更新日と更新者を表示する
- ユーザ毎のコミット回数とメッセージを一覧表示する
- 誰かの作業を上書きしない場合、リモートに強制的にpushする
- ユーザが貢献した行数を表示する
- 全てのマージをリバートする
- ブランチのコミット回数を表示する
- エイリアス git undo
- オブジェクトノートを追加する
- 全てのオブジェクトノートを表示する
- 別のリポジトリからコミットを適用する
- 特定のリモートブランチからfetchする
- 2つのブランチから共通の祖先を見付ける
- pushしてないコミットを表示する
- 空白以外の変更をapplyする
- ローカル/グローバルのgitコンフィグを編集する
- 指定範囲内をblameする
- Git変数を表示する
- 整形済みのパッチを作成する
- リポジトリのルート絶対パスを取得する
- 特定期間のログを表示する
- 指定者以外のログを表示する
- ペンディング中の変更のまとめを作成
- リモートリポジトリのブランチを表示する
- Git管理していないファイルをバックアップする
- エイリアスを一覧表示する
- git statusを簡潔に表示する
- 昨日のコミットをチェックアウトする
- ローカルブランチをリモートリポジトリにpushして追跡する
- ブランチのベースを変更する
- HTTPsではなくSSHをリモートへの接続に使用する
git help everydaygit help -ggit log -S'<a term in the source>'git fetch origin && git reset --hard origin/master && git clean -f -dgit ls-tree --name-only -r <commit-ish>git update-ref -d HEADgit diff --name-only --diff-filter=Ugit diff-tree --no-commit-id --name-only -r <commit-ish>git diffgit diff --cachedその他の方法:
git diff --stagedgit diff HEADgit branch --merged mastergit checkout -その他の方法:
git checkout @{-1}git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -dその他の方法:
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked outgit branch -vvgit branch -u origin/mybranchgit branch -d <local_branchname>git push origin --delete <remote_branchname>その他の方法:
git push origin :<remote_branchname>git tag -d <tag-name>git push origin :refs/tags/<tag-name>git checkout -- <file_name>git revert <commit-ish>git reset <commit-ish>git commit -v --amendgit cherry -v mastergit commit --amend --author='Author Name <[email protected]>'git commit --amend --reset-author --no-editgit remote set-url origin <URL>git remoteその他の方法:
git remote showgit branch -agit branch -rgit add -pcurl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrcgit log --no-merges --raw --since='2 weeks ago'その他の方法:
git whatchanged --since='2 weeks ago'git log --no-merges --stat --reverse master..git checkout <branch-name> && git cherry-pick <commit-ish>git branch -a --contains <commit-ish>その他の方法:
git branch --contains <commit-ish>git config --global alias.<handle> <command>
git config --global alias.st statusgit stashその他の方法:
git stash savegit stash -kその他の方法:
git stash --keep-indexgit stash save --keep-indexgit stash -uその他の方法:
git stash save -ugit stash save --include-untrackedgit stash save <message>git stash -aその他の方法:
git stash --allgit stash save --allgit stash listgit stash apply <stash@{n}>git stash popその他の方法:
git stash apply stash@{0} && git stash drop stash@{0}git stash clearその他の方法:
git stash drop <stash@{n}>git checkout <stash@{n}> -- <file_path>その他の方法:
git checkout stash@{0} -- <file_path>git ls-files -tgit ls-files --othersgit ls-files --others -i --exclude-standardgit worktree add -b <branch-name> <path> <start-point>git worktree add --detach <path> HEADgit rm --cached <file_path>その他の方法:
git rm --cached -r <directory_path>git clean -ngit clean -fgit clean -f -dgit submodule foreach git pullその他の方法:
git submodule update --init --recursivegit submodule update --remotegit cherry -v masterその他の方法:
git cherry -v master <branch-to-be-merged>git branch -m <new-branch-name>その他の方法:
git branch -m [<old-branch-name>] <new-branch-name>git rebase master feature && git checkout master && git merge -git archive master --format=zip --output=master.zipgit add --all && git commit --amend --no-editgit fetch -pその他の方法:
git remote prune origin git rev-list --reverse HEAD | head -1その他の方法:
git rev-list --max-parents=0 HEADgit log --pretty=oneline | tail -1 | cut -c 1-40git log --pretty=oneline --reverse | head -1 | cut -c 1-40git log --pretty=oneline --graph --decorate --allその他の方法:
gitk --allgit log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)git subtree push --prefix subfolder_name origin gh-pagesgit subtree add --prefix=<directory_name>/<project_name> --squash [email protected]:<username>/<project_name>.git mastergit subtree pull --prefix=<directory_name>/<project_name> --squash [email protected]:<username>/<project_name>.git mastergit bundle create <file> <branch-name>git clone repo.bundle <repo-dir> -b <branch-name>git rev-parse --abbrev-ref HEADgit update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changeloggit rebase --autostashgit fetch origin pull/<id>/head:<branch-name>その他の方法:
git pull origin pull/<id>/head:<branch-name>git describe --tags --abbrev=0git diff --word-diffgit difftool [-t <tool>] <commit1> <commit2> <path>git update-index --assume-unchanged <file_name>git update-index --no-assume-unchanged <file_name>git clean -X -fgit checkout <deleting_commit>^ -- <file_path>git checkout <commit-ish> -- <file_path>git config --global pull.rebase trueその他の方法:
#git < 1.7.9
git config --global branch.autosetuprebase alwaysgit config --listgit config --global core.ignorecase falsegit config --global core.editor '$EDITOR'git config --global help.autocorrect 1git name-rev --name-only <SHA-1>git clean -fd --dry-rungit commit --fixup <SHA-1>git rebase -i --autosquashgit commit --only <file_path>git add -igit check-ignore *git status --ignoredgit log Branch1 ^Branch2git log -<n>その他の方法:
git log -n <n>git config --global rerere.enabled 1git diff --name-only | uniq | xargs $EDITORgit count-objects --human-readablegit gc --prune=now --aggressivegit instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]git log --show-signaturegit config --global --unset <entry-name>git checkout --orphan <branch_name>git show <branch_name>:<file_name>git log --first-parentgit rebase --interactive HEAD~2git checkout master && git branch --no-mergedgit bisect start # Search start
git bisect bad # Set point to bad commit
git bisect good v2.6.13-rc2 # Set point to good commit|tag
git bisect bad # Say current state is bad
git bisect good # Say current state is good
git bisect reset # Finish search
git commit --no-verifygit log --follow -p -- <file_path>git clone -b <branch-name> --single-branch https://github.com/user/repo.gitgit checkout -b <branch-name>その他の方法:
git branch <branch-name> && git checkout <branch-name>git config core.fileMode falsegit config --global color.ui falsegit config --global <specific command e.g branch, diff> <true, false or always>git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/git grep --heading --line-number 'foo bar'git clone https://github.com/user/repo.git --depth 1git log --all --grep='<given-text>'git log --oneline master..<branch-name> | tail -1その他の方法:
git log --reverse master..<branch-name> | head -6git reset HEAD <file-name>git push -f <remote-name> <branch-name>git remote add <remote-nickname> <remote-url>git blame <file-name>git shortloggit push --force-with-lease <remote-name> <branch-name>git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += <!-- @doxie.inject start -->; subs += <!-- @doxie.inject end -->; loc += <!-- @doxie.inject start --> - <!-- @doxie.inject end --> } END { printf "added lines: %s removed lines: %s total lines: %s
", add, subs, loc }' -その他の方法:
git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += <!-- @doxie.inject start -->; subs += <!-- @doxie.inject end -->; loc += <!-- @doxie.inject start --> - <!-- @doxie.inject end --> } END { printf "added lines: %s, removed lines: %s, total lines: %s
", add, subs, loc }' - # on Mac OSXgit revert -m 1 <commit-ish>git rev-list --count <branch-name>git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'git notes add -m 'Note on the previous commit....'git log --show-notes='*'git --git-dir=<source-dir>/.git format-patch -k -1 --stdout <SHA1> | git am -3 -kgit fetch origin master:refs/remotes/origin/mymasterdiff -u <(git rev-list --first-parent BranchA) <(git rev-list --first-parent BranchB) | sed -ne 's/^ //p' | head -1git log --branches --not --remotesその他の方法:
git log @{u}..git cherry -vgit diff --ignore-all-space | git apply --cachedgit config [--global] --editgit blame -L <start>,<end>git var -l | <variable>git format-patch -M upstream..topicgit rev-parse --show-toplevelgit log --since='FEB 1 2017' --until='FEB 14 2017'git log --perl-regexp --author='^((?!excluded-author-regex).*)
git request-pull v1.0 https://git.ko.xz/project master:for-linusgit ls-remote git://git.kernel.org/pub/scm/git/git.gitgit ls-files --others -i --exclude-standard | xargs zip untracked.zipgit config -l | grep alias | sed 's/^alias\.//g'その他の方法:
git config -l | grep alias | cut -d '.' -f 2git status --short --branchgit checkout master@{yesterday}git push -u origin <branch_name>git rebase --onto <new_base> <old_base>git config --global url.'[email protected]:'.insteadOf 'https://github.com/'