Tab complete your recent git commits
If you like bash-completion, you can make your own. I've been tinkering around with making a bash completion to make it easier to push a specific git commit. My old workflow for pushing a specific commit used to be this:
- rebase, move commits around
- git log, see the commit id, copy the id
- git push origin <commit-id>:master
I got tired of doing this, so I created this bash completion: https://gist.github.com/joeheyming/5a3892afda9db4789987
function pushCommit() {
git push origin $1:master;
}
function _pushCommit() {
local RECENT_COMMITS=`git log --pretty=oneline master..HEAD`
COMPREPLY=()
local cur
cur=$(_get_cword)
local OLDIFS="$IFS"
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$RECENT_COMMITS" -- "$cur" ) )
IFS="$OLDIFS"
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then #Only one completion
COMPREPLY=( ${COMPREPLY[0]%% *} ) #Remove ' ' and everything after
fi
return 0
}
complete -F _pushCommit pushCommit
Now I just type my function:
bash
pushCommit <<TAB>>
1804c645dcbac9dd361c29ae1531ff96e8 Fixed the bug.
6690badf47395ecde6fd7d8d81fbf8a0a7 Super cool new feature.
and I see the most recent commits on my branch up to my local master. (with the subject of the commit)
Try it out! What do you think? I'd like to know if you have similar issues with other git commands.
Written by Joe Heyming
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#