Skip to content

Instantly share code, notes, and snippets.

@schtibe
Last active July 31, 2017 09:17
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 schtibe/98f50f6c9c405b672e51b2841d11c50a to your computer and use it in GitHub Desktop.
Save schtibe/98f50f6c9c405b672e51b2841d11c50a to your computer and use it in GitHub Desktop.
Bash function to view a file in $EDITOR at a certain commit
function gshow() {
tmp_dir=$(mktemp -d)
filename=$(basename $2)
tmp_path="$tmp_dir/$filename"
git show $1:$2 > $tmp_path
$EDITOR $tmp_path
rm $tmp_path
rmdir $tmp_dir
}
@schtibe
Copy link
Author

schtibe commented Jul 25, 2017

Motivation

To be able to see a file in your git repository at a certain revision. This can easily be done with git show <rev> <file>, but I want it to have in my editor of choice with syntax highlighting turned on (which is why the temporary file is needed, to preserve the extension)

Usage

Put this into your ~/.bashrc, then you cann use it with gshow <revision> <file>, e.g. gshow 3f51bc4d74ec1ca054a7197be16e6fe095c78b88 export.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment