Wrote up a basic View In Editor menu item that will extract a read-only version of a file at a specific commit as an alternative to Open In Editor that only opens the HEAD version.
The menu item is implemented using a git alias which also allows command line usage if wanted:
git smerge-view-in-editor path/to/file commit-ish
-
git smerge-view-in-editor path/to/file commit-ish 10
(at line 10)
Notes/Caveats:
- always creates a read-only temporary file, regardless of if it’s on the current branch or not
- viewing a file from Commit Changes will always open a blank file due an invalid/non-existent commit
Steps:
-
add this git alias:
git config --global alias.smerge-view-in-editor '!f() { local file="${1#"$PWD"}" local commit="${2:-HEAD}" local line="${3:-1}" local temp_file="$(mktemp -d)" temp_file="$temp_file/$(basename "$temp_file").$(basename "$file")" git show "$commit:$file" > "$temp_file" chmod a-wx "$temp_file" subl "$temp_file:$line" }; f'
-
add this menu item to
File.sublime-menu
:[ { "caption": "View in Editor…", "command": "git", "args": { "argv": ["smerge-view-in-editor", "$path", "$commit", "1"] } } ]
-
add this menu item to
Diff Context.sublime-menu
:[ { "caption": "View in Editor…", "command": "git", "args": { "argv": ["smerge-view-in-editor", "$path", "$commit", "$line"] } } ]