LoginSignup
13
12

More than 5 years have passed since last update.

gitの変更があるファイルを一括でエディタで開く

Last updated at Posted at 2015-11-10

できること

  • 現在変更のあるファイルを一気にエディタで開く
    • $ git open
  • あるリビジョンで変更のあったファイルを一気にエディタで開く
    • $ git open show abcdef
  • 他、gist参照

使っているエディタはSublime Text

エディタでタブが開き過ぎていて一度リセットしたい時などに、すべて閉じてからgit openを使うと楽

元となった記事

Open all files from a git diff or git show with this handy command utility

元のGist gitopen.sh

設定方法

  • EDITORの部分を変える
  • ~/binなどにパスを通して、その下に配置しておく
  • gitのaliasを設定 (~/.gitconfig)
    • [alias]のところにopen = !sh ~/bin/gitopen.shを追加
    • もしかして~/bin/git-openにすればalias無しで動く?(未確認)
gitopen.sh
#!/bin/bash

# This script will open all files from a git diff or a git show in vim.

# My bash skills are a bit primitive so this can probably be done more intelligently

# Usage:
#   gitopen -- opens all added files that have changed since HEAD
#   gitopen diff HEAD -- these are the default parameters
#   gitopen diff master -- opens files that have changed from master
#   gitopen show -- opens files that were changed in the last revision (HEAD)
#   gitopen show HEAD -- default param, does the same
#   gitopen show 4b3ca34 -- opens a particular REV

# It's set to use macvim as the default editor, you can change that easily by
# changing this line:
EDITOR=subl

COMMAND=diff
REV=HEAD

if [ $1 ]; then
    COMMAND=$1
fi

if [ $2 ]; then
    REV=$2
fi

if [ $COMMAND = "show" ]; then
    PARAM='--pretty=format: --name-only'
else
    PARAM='--name-only'
fi

git $COMMAND $PARAM $REV | xargs $EDITOR

その他

GitHubのページをブラウザで開く別のgit openもあった

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12