handy git tricks - linaro · git status --porcelain (to parse output to scripts, backwards...

7
Handy Git tricks Viresh Kumar (Linaro)

Upload: others

Post on 25-Aug-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Handy Git tricks - Linaro · 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

Handy Git tricksViresh Kumar (Linaro)

Page 2: Handy Git tricks - Linaro · 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

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

Page 3: Handy Git tricks - Linaro · 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

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

Page 4: Handy Git tricks - Linaro · 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

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

Page 5: Handy Git tricks - Linaro · 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

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)

Page 6: Handy Git tricks - Linaro · 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

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

Page 7: Handy Git tricks - Linaro · 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

[email protected]