これらのコミットを時系列で持っているとしましょう:
- a
- b
- c
b
今、私は cを取り除きたいのですが、私が持っているように:
- a
- c
どうすればいいですか?
b
( と の間に競合はありませんc
)
これらのコミットを時系列で持っているとしましょう:
b
今、私は cを取り除きたいのですが、私が持っているように:
どうすればいいですか?
b
( と の間に競合はありませんc
)
すでに変更をリモートにプッシュしている場合は、次を使用できます。
$ git revert <hash of commit b>
d
コミットの変更を削除する新しいコミットを作成するb
HEAD からのコミットが 1 つだけ必要な場合は、別のブランチで cherry-pick を使用して、そのコミットだけを持ち込むことができます。
$ git checkout -b working
$ git reset --hard <hash of the commit `a`>
$ git cherry-pick <hash of the commit `c`>
ハードリセットは作業コピーをそのコミット時の状態に戻し、チェリーピックはコミットで導入された変更をc
作業コピーの上に直接適用します。
git rebase のヘルプは、まさにこのケースについて語っています! 見てみな:
A range of commits could also be removed with rebase. If we have the
following situation:
E---F---G---H---I---J topicA
then the command
git rebase --onto topicA~5 topicA~3 topicA
would result in the removal of commits F and G:
E---H'---I'---J' topicA
This is useful if F and G were flawed in some way, or should not be
part of topicA. Note that the argument to --onto and the <upstream>
parameter can be any valid commit-ish.
まだリモート リポジトリにプッシュしていないと仮定すると、インタラクティブなリベースを実行できます。ここを参照してください: