LoginSignup
9
10

More than 5 years have passed since last update.

gitで差分ファイルを抽出する(改変)

Last updated at Posted at 2014-12-18

gitで差分取ってzipするやつ、少し改変して使わせてもらった。

.bashrc

function git_diff_archive() 
{
  dateTime=`date '+%Y%m%d%H%M'`
  local diff=""
  local h="HEAD"
  if [ $# -eq 1 ]; then
    if expr "$1" : '[0-9]*' > /dev/null ; then
      diff="HEAD HEAD~${1}"
    else
      diff="HEAD ${1}"
    fi
  elif [ $# -eq 2 ]; then
    diff="${1} ${2}"
    h=$1
  fi
  if [ "$diff" != "" ]; then
    diff="git diff --name-only ${diff}"
  fi
  git archive --format=zip $h `eval $diff` -o ${PWD##*/}-$dateTime.zip
}
alias git_diff_archive=git_diff_archive

ちょっといじったのはzipで固めるファイル名。
今いるディレクトリ名-yyyyMMddHHmm.zip にする。
repo のルートにいないとダメですかそうですか。

$ git_diff_archive ab8c41c

repo のルートで打つと、hogehoge-201412121330.zip ができる。

9
10
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
9
10