🖥
#git で 新しいブランチを切って、すぐに同じ名前で空のコミットを作成するコマンドと gitconfig エイリアスの例
コマンド
-
git checkout -b
で現在のブランチから新しいブランチを作り、すぐに新ブランチにcheckoutできる - git commit --allow-empty で空のコミットを作成できる
-
$()
の中は現在のブランチ名を、シェルで頑張って切り取っている - これをコミットメッセージの内容として指定している
git checkout -b <BRANCH_NAME> && git commit --allow-empty -m "$( git branch | grep '* ' | sed 's/* //g' | head -n 1)"
実行例
git checkout -b <BRANCH_NAME> && git commit --allow-empty -m "$( git branch | grep '* ' | sed 's/* //g' | head -n 1)"
Switched to a new branch 'some'
[some e9c64562] master
確認
commit 3a75169fa3b1c34c136625d93105dxb6fdd2b0e0 (HEAD -> some)
Author: YumaInaura <yuma.inaura@gmail.com>
Date: Mon Dec 30 15:51:35 2019 +0900
.gitconfig
[alias]
current-branch-name = ! git branch | grep -e '^\\* ' | sed -e 's/^\\* //g'
commit-by-current-branch-name = ! git commit --allow-empty -m "$(git current-branch-name)"
checkout-new-branch-and-commit-empty = "!f() { git checkout -b \"$1\" && git commit-by-current-branch-name; }; f"
run
git checkout-new-branch-and-commit-empty YA
Switched to a new branch 'YA'
[YA 223ae3d5] YA
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-12-31
Discussion