Git useful scripts

Creating more alias on Ubuntu
Edit or create if this file isn't existed. You could create alias or function.

sudo vi ~/.bash_aliases

# add this alias
source ~/.bash_git_aliases.sh
alias myAlias="echo Do something"

Create file ~/.bash_git_aliases.sh

sudo vi ~/.bash_git_aliases.sh

function gitlogsearch()
{
if [[ -z $1 ]]; then
echo -e "Please provide the strings to search"
return 1
else
search_string=$1
fi

if [[ -z $2 ]]; then
commit_since=yesterday
else
commit_since=$2
fi

echo -e "Searching for commit messages which have strings ${search_string} since ${commit_since}"
git log --color --graph --decorate=short --source --all --after=${commit_since} --grep=${search_string}
git submodule foreach git log --color --graph --decorate=short --source --all --after=${commit_since} --grep=${search_string}
}

function gitlogsearchstring()
{
if [[ -z $1 ]]; then
echo -e "Please provide the strings to search"
return 1
else
search_string=$1
fi

if [[ -z $2 ]]; then
commit_since=yesterday
else
commit_since=$2
fi

echo -e "Searching for commits which change strings ${search_string} since ${commit_since}"
git log --color --graph --decorate=short --source --all --after=${commit_since} -S ${search_string}
git submodule foreach git log --color --graph --decorate=short --source --all --after=${commit_since} -S ${search_string}
}


Open a new terminal and go to a git repo

Searching for commit messages which have strings YOUR_STRINGS since YEAR-MONTH-DAY

# Search any commit messages which have YOUR_STRINGS
gitlogsearch YOUR_STRINGS YEAR-MONTH-DAY

Searching for commits which change strings YOUR_STRINGS since YEAR-MONTH-DAY

# Search any changes which have YOUR_STRINGS
gitlogsearchstring YOUR_STRINGS YEAR-MONTH-DAY

Loading