Skip to content

Instantly share code, notes, and snippets.

@olivierperez
Last active December 18, 2015 14:33
Show Gist options
  • Save olivierperez/625da5fc99f2cdeaf3e1 to your computer and use it in GitHub Desktop.
Save olivierperez/625da5fc99f2cdeaf3e1 to your computer and use it in GitHub Desktop.
Git - Script that return the last changes
#!/bin/bash
# git-last - Return the last changes (last commit, staged changes, current changes)
# Copyright (C) 2015 Olivier Perez <olivier@olivierperez.fr>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
last_commit() {
echo "----------"
local msg=`git log -1 --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'`
echo "Last commit: $msg"
git diff --stat HEAD~1
}
staged() {
local x=`git diff --cached --stat --color`
local stagedwc=`echo $x | wc -w`
echo
echo "----------"
if [[ $stagedwc == "0" ]]; then
echo "No staged changes"
else
echo "Staged changes"
echo "$x"
fi
}
diff() {
local diff=`git diff --stat --color`
local diffwc=`echo $diff | wc -w`
echo
echo "----------"
if [[ $diffwc == "1" ]]; then
echo "No current changes"
else
echo "Current changes"
echo "$diff"
fi
}
last_commit
staged
diff
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment