Post on 25-Aug-2020
Handy Git tricksViresh Kumar (Linaro)
Git rebase● Everyone has done ‘git rebase -i’● Have you played with .git/rebase-merge/git-rebase-todo*
● git rebase --onto● git rebase --autosquash
○ git commit --fixup and --squash
● Want to skip the editor part ?
○ GIT_EDITOR=cat git rebase --autosquash○ GIT_EDITOR=cat git rebase --continue○ GIT_EDITOR=cat git revert -s○ GIT_EDITOR=cat git commit --amend
Git repo management● git stash helps in managing uncommitted changes● git reflog is quite helpful in finding HEAD history (to find deleted commits)
● git clone --reference=<local-tree> (--disassociate)● git worktree (Two trees using same sha’s, branches, etc)
○ git worktree add ~/android android-4.9
Git misc. commands● git reset:
○ Powerful and useful, but risky.
○ Handle with care○ rm -rf *; git reset --hard HEAD○ Many useful variants --soft, --hard, --keep
● git checkout: a branch, file or directory.○ git checkout <branch>○ git checkout -b <branch> <sha1>○ git checkout <sha1> -- drivers/cpufreq/cpufreq.c
Git misc. commands (Cont.)● git add:
○ Add all changes of a file/directory and update index○ Working directory -> Index -> commit ○ git add -p
■ Allows to Move only part of changes to index.■ Makes is easy to create several commits out of a diff.
● git diff:○ git diff branchA..branchB (double dot)○ git diff branchA...branchB (triple dot)
Git misc. commands (Cont.)● git log:
○ git log branchA..branchB (double dot)○ git log branchA...branchB (triple dot)○ git log --reverse branchA..branchB○ git log --stat -p○ git log -S’<string>’ or git log -G’<regex>’
○ git log --follow
● git show --stat -p --word-diff● git status --porcelain (to parse output to scripts, backwards compatible.
=v2 for more info)● git grep, bisect, describe● git fetch -p and git push --mirror
Thank youJoin Linaro to accelerate deployment of your Arm-based solutions through collaboration
contactus@linaro.org