LoginSignup
2
0

More than 3 years have passed since last update.

一部の行だけ特定のコミット状態に戻す

Last updated at Posted at 2019-06-28

「この機能はやっぱり必要ない」という指示を受けて、一部の行だけ削除。
その後も開発を進めて何度もコミットを繰り返してから「やっぱりあの機能を戻して:smiling_imp:」という指示。
私はよくあります:cry:

一部の行だけあのときに

git checkout -p <commit> <file>

Hunkに基づいてワーキングツリーとステージングに上げたファイルを元に戻すか問われます。
Apply this hunk to index and worktree [y,n,q,a,d,s,e,?]?
この問いにy,nで答える。

今ワーキングツリーで編集中のファイルがステージングに上がってない場合、
The selected hunks do not apply to the index!
Apply them to the worktree anyway?
追加で質問されるのでy

思うように分割されていないとき

sでもっと細かく分割してくれます。

それでも上手くいかないとき

eで手作業で編集します。

現状を保持したいなら、
-行の - を空白に変える
+行は丸ごと削除

2
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
2
0