0
0

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 1 year has passed since last update.

Git にて特定のコミットハッシュの内容を手元で再現する手順

Last updated at Posted at 2023-10-11

要約

  • リモートリポジトリから特定のコミットを取得し、現在のブランチをそのコミットにハードリセットします。
# リモートリポジトリから特定のコミット(<hash値>で指定)を取得し、
# 浅いクローン(shallow clone)を行います。
git fetch --depth 1 origin <hash値>
# 現在のブランチがFETCH_HEADの位置に強制的に移動し、
# ワーキングディレクトリがリセットされ、最新のコミット状態になります。
git reset --hard FETCH_HEAD

MEMO:

  • 既にマージされちゃってたり、リバートされちゃってたりして、
    「HEADだと不都合だけど、この時のこのコミットで動作確認などをしたいとき」。
  • ピンポイントでコミットハッシュ(SHA)をベースに手元に状態を復元!
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?