Git cheat sheet
Git のよく使ったりたまにしか使わないから忘れるコマンドたち git commit --fixup <commit-ref>
git rebase -i --autosquash <commit-ref>
Stash
stash の diff を確認する
git stash show -p <name>
name で restore する
code:shell
git stash apply stash^{/STASH_NAME}
Pull rebase
GitHub で suggest 受けて UI で commit した。その間にもローカルの履歴が進んでいる。当然ただ pull すると ff にならないので rebase option をつける
code:shell
git pull origin branch -r
Check status changes
code:shell
git status -v
任意の commit のときのファイルの状態を知る
code:terminal
git show <commit>:<file>
code:terminal
git reset --hard origin/branchname
Cleanup
remove merged branches
$ git branch --merged | grep -v '*' | xargs -I % git branch -d %
remote tracking branchs
$ git fetch --prune
$ git remote prune origin
Squash all commit into one
code:terminal
git reset $(git commit-tree HEAD^{tree} -m "initila commit")
Setup remote repository
code:terminal
git remove -v // Show remote repositories
git remote add upstream git@github.com:madoka/magika.git
Merge without merge commit
code:shell
git merge <branch> --no-commit
Modify old commit message
code:shell
git rebase -i ...
use reword directive
Diff
Diff of commit A and parent commit of A
code:shell
git diff A^ A
Switch to remote branch
$ git fetch origin
$ git switch -c branch_name
if there is origin/branch_name, branch_name branch will be created
$ git switch -c branch remote/branch
これ使っておけば間違いない
$ git switch --detach branch_name
reflog
git reset <reflog で確認したid>