最近几年的工作,零零碎碎也积累了一些 git 的常用操作
本文统一做一个归纳,方便以后的查阅或给予他人帮助
或许一些常用的对比操作、清理维护操作,可以抽象成一个工具,方便可视化使用 👍🏻
本地分支维护
清理已经合入的分支
1 | git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d |
Or if you just wanna do dry-run
(see what’s going to happen), remove | xargs git branch -d
part
Show git log as one line (And find my own commit)
1 | git log --pretty=format:"%h - %an - %s" | grep -E "myName|我的名字" |
Compare two branches
1 | # find commits that in `branch_b` but not in `branch_a` |
To check whether there are unresolved conflicts
(although brutally search <<< / >>>
works too)
1 | git diff --check |
Just create new branch without checkout
1 | # This is what I usually do, |
搜索历史 commit 中的内容
HEAD UP: repo with tons of commits may suffer performance issue
1 | git grep "content" $(git rev-list --all) |