0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

番号選んでタイトル入れて本文入れたら完成!

function com() {
  local prefixes=(
    "fix: 既存の機能の問題を修正する場合に使用します。"
    "hotfix: 緊急の変更を追加する場合に使用します。"
    "add: 新しいファイルや機能を追加する場合に使用します。"
    "feat: 新しい機能やファイルを追加する場合に使用します。"
    "update: 既存の機能に問題がないが、修正を加えたい場合に使用します。"
    "change: 仕様変更により、既存の機能に修正を加えた場合に使用します。"
    "clean/refactor: コードを修正し、改善する場合に使用します。"
    "improve: コードの改善をする場合に使用します。"
    "disable: 機能を一時的に無効にする場合に使用します。"
    "remove/delete: ファイルを削除する場合や、機能を削除する場合に使用します。"
    "rename: ファイル名を変更する場合に使用します。"
    "move: ファイルを移動する場合に使用します。"
    "upgrade: バージョンをアップグレードする場合に使用します。"
    "revert: 以前のコミットに戻す場合に使用します。"
    "docs: ドキュメントを修正する場合に使用します。"
    "style: コーディングスタイルの修正をする場合に使用します。"
    "perf: コードのパフォーマンスを改善する場合に使用します。"
    "test: テストコードを修正する場合や、テストコードを追加する場合に使用します。"
    "chore: ビルドツールやライブラリで自動生成された、その他。"
  )

  echo "コミットメッセージのプレフィックスを選択してください。"
  for i in {1..${#prefixes[@]}}; do
    echo "$i. ${prefixes[$i]}"
  done

  read "number?番号を入力してください: "
  if (( number < 1 || number > ${#prefixes[@]} )); then
    echo "無効な番号です。"
    return 1
  fi

  local selected_prefix="${prefixes[$number]}"
  local prefix=$(echo "$selected_prefix" | cut -d' ' -f1)

  read "title?コミットタイトルを入力してください: "

  echo "コミット本文を入力してください。終了するにはCtrl+Dを押してください。"
  local message_body=""
  while IFS= read -r line; do
    message_body+="${line}\n"
  done

  local commit_message="${prefix} ${title}\n\n${message_body}"
  git commit -m "$(echo -e "${commit_message}")"
}

おまけ: 過去の commit に現状の変更を加える

function git-fixup() {
  git log --oneline -n 10

  read "現在の変更を加えたいHashを入力: "
  git add .
  git commit --fixup=$commit_hash
  GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash ${commit_hash}^

  echo "対象のコミットに変更を加えました。"
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?