Tuesday, October 6, 2015
Script to find repositories with unstaged/uncommited changes
I found this nice script that I often use to check if I did not forget to push the latest changes to git.Here are some instructions on how to use it:
- Save the snippet below to a file and name it something like multipleStatus.sh;
- Place the file on the same folder of your repositories;
- To run the script, browse to that folder and type:
source multipleStatus.sh; find-dirty
And here is the snippet you need to save:
#!/bin/bash
function unstaged_changes() {
worktree=${1%/*};
git --git-dir="$1" --work-tree="$worktree" diff-files --quiet --ignore-submodules --
}
function uncommited_changes() {
worktree=${1%/*};
git --git-dir="$1" --work-tree="$worktree" diff-index --cached --quiet HEAD --ignore-submodules --
}
function find-dirty () {
for gitdir in `find . -name .git`;
do
worktree=${gitdir%/*};
if ! unstaged_changes $gitdir
then
echo "unstaged $gitdir"
fi
if ! uncommited_changes $gitdir
then
echo "uncommitted $gitdir"
fi
done
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment