links: 010 Vim MOC
Note: ~/.gitconfig is pushed to github dotfiles repo. sync it with new computer for using aliases
git stat alias
While reviewing pull request, when you checkout branch locally you might want to see what changes are made compared to the source branch (typically master/staging). The git stat alias can do this
- list which files changed
- how many lines changed in each file (additions and deletions)
- how many lines changed overall
What does git stat do under the hood?
stat = "!f() { review_base=${1-master}; git diff --stat $(git merge-base HEAD \"$review_base\"); }; f"This utilizes git diff and git merge-base and runs a bash command with one argument which is defaults to master. This argument can be specified if you want to compare the current branch with the branch you want
Usage:
git stat // compares current branch with master
git stat staging // compares current branch with staging
git stat HEAD^ // compares the last commit of this branch
git stat <branch-name> // branch-name is optional and defaults to master
git stat <commit-identifier> // commit-identifier is optional and defaults to mastergit review alias
This command compares current branch to the branch passed in the command (defaults to master) and gets list of files and opens them in vim tabs
Usage:
git review // compares current branch with master branch
git review staging // compares current branch with staging branchWhat does git review do under the hood
review = "!f() { review_base=${1-master}; vim -p $(git files) +\"tabdo Gdiff $review_base\" +\"let g:gitgutter_diff_base = '$review_base'\"; }; f"- This will open all files ($(git files))
- runs fugitive’s Gdiff on each tab with branch passed in command line
git reviewone alias
This command is similar to git review the only change is it takes list of files to open in vim
Usage:
git reviewone master package.json app.tsx // takes branch to compare with and list of files
git reviewone <branch_name> file1 file2 ...What does git review do under the hood
reviewone = "!f() { \
if [ $# -lt 2 ]; then \
echo Usage: git reviewone branch_name file1 file2; \
else\
review_base=${1}; \
vim -p ${@:2} +\"tabdo Gdiff $review_base\" +\"let g:gitgutter_diff_base = '$review_base'\"; \
fi;\
}; f"- This checks for minimum of two arguments (first branch name and atleast one file name)
- If there are less than 2 args, it echoes usage description
- else, pipes all the args to vim except first arg as it’s branch name (vim -p ${@:2})
- vim opens list of files in tabs and uses Gdiff to show comparison