3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gitのお作法~失敗談を添えて~

3
Posted at

ファイルやディレクトリ名を変更、移動、削除する

ローカルのファイルをエクスプローラーでリネームしたら、git で差分として認識されなかった。
しかも、以後そのファイルをgitが追跡できなくなった。

→ファイルのリネーム、削除はgitのコマンドで行う。

ファイルの削除
$ git rm <file>
ファイルの移動、リネーム
$ git mv <oldfilename> <newfilename>

変更したファイルを元に戻す

Laravelで過去のマイグレーションファイルをいじるのはNGというルールを忘れ、いじってしまった。そのうえgitを導入しているにもかかわらず、またそのファイルを手で書き換えて元に戻した。結果、正確に元の状態に戻っていないことに。。。

→gitで過去のコミットを打ち消すことでファイルを元の状態に戻す。

コミットの打ち消しとは??
特定コミットの処理を、うち消すコミットを作成する。コミットログとしては、誤ったコミットとそれを打ち消すためのコミットの2つが残る。過去の履歴を書き換えないので、安全に取り消しが行える。

$ git revert <打ち消すコミットID>

<メモ>
git revert をするとき、お尻から revert しないとコンフリクトが発生した。git revert --abortでrevert自体の取り消しをして、お尻からrevertをして解決。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?