Skip to content

Instantly share code, notes, and snippets.

@achalddave
Last active April 14, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achalddave/d45867a3cd1ec7505b84a5e6648a4a8a to your computer and use it in GitHub Desktop.
Save achalddave/d45867a3cd1ec7505b84a5e6648a4a8a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Save current git diff, log, status to output directory.
#
# Example usage:
# ./dump_git_info.sh /path/to/output/directory/
# ./dump_git_info.sh /path/to/output/directory/ /path/to/git/repo/
#
# Writes the following files to output_dir:
#
# git-status.txt: Output of git status -sb.
# git-log.txt: Output of
# git log --graph --pretty='format:%h -%d %s (%cd) <%an>'
# git-diff.patch: Output of git diff --patch --color=never
# git-head.txt: Output of git rev-parse HEAD
function usage {
echo "Usage: "
echo "$0 <output_directory> [<git_dir>]"
}
if [[ "$#" != 1 ]] && [[ "$#" != 2 ]] ; then
echo "Incorrect usage."
usage
exit 1
fi
OUTPUT_DIR=$(readlink -f "$1")
if [[ "$#" == 2 ]] ; then
cd "$2"
fi
git diff --patch --color=never > "${OUTPUT_DIR}/git-diff.patch"
git log --graph --pretty='format:%h -%d %s (%cd) <%an>' \
> "${OUTPUT_DIR}/git-log.txt"
git rev-parse HEAD > "${OUTPUT_DIR}/git-head.txt"
git status -sb > "${OUTPUT_DIR}/git-status.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment