1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【ノート】Git① コミット修正 git commit --amend --no-editの使い方

1
Posted at

1. git commit --amendとは

ローカルのGitで、直前のコミットに間違いがあったとき
そのコミットを最新の状態を保ったまま上書きできる。

--amendを使うメリット

git resetでコミットを取り消さなくても、きれいなコミット1つに上書きできる

--no-editオプション

これをつけると、コミットメッセージはそのまま、中身だけを差し替えてくれる。

2.git commit --amendを使う場面

例1. 必要な設定ファイルがコミットから漏れていた

git add (ファイル)
git commit --amend -no-edit

例2. コミットメッセージを修正したい

git commit --amend -m "修正後のメッセージ"

例3. 誤って.envをコミットしてしまった

git rm --cached .env
git commit --amend --no-edit

注意点

  • push済みのコミットにはamendを極力使わない(=push前にamendで修正する)
  • チーム開発では運用ルールに従い慎重に使う
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?