Last active
July 31, 2017 09:17
-
-
Save schtibe/98f50f6c9c405b672e51b2841d11c50a to your computer and use it in GitHub Desktop.
Bash function to view a file in $EDITOR at a certain commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 withgshow <revision> <file>
, e.g.gshow 3f51bc4d74ec1ca054a7197be16e6fe095c78b88 export.py
.