LoginSignup
0
3

More than 5 years have passed since last update.

Gitで過去のコミットをやり直す

Posted at

git rebaseを使う

修正したいコミットのIDを確認

git log

修正したいコミットを指定

修正したいコミットの一個前のコミットIDを指定する
そして少し待つ

git rebase -i <commit>

-i--interactiveの略で、対話的にリベースする

修正したいコミットをeditに変更

以下のように指定したコミットより後のコミットが表示される

pick gh21f6d ヘッダー修正
pick 193054e ファイル追加
pick 84gha0d README修正

pickの部分をeditに変える

edit gh21f6d ヘッダー修正
pick 193054e ファイル追加
pick 84gha0d README修正

保存はctl + xの後、yes/noを聞かれるのでYを押してエンター

ファイルを修正

タイトルだけ変えたい場合はここでは何もしない

修正を反映

git commit --amend

rebaseを実行

git rebase --continue

こんな感じの文章が出てくる

$ git rebase --continue
Successfully rebased and updated refs/heads/refactoring.
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

warning: There are too many unreachable loose objects; run 'git prune' to remove them.

(参考)
https://www.backlog.jp/git-guide/reference/log.html

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