24
26

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で特定のコミット(リビジョン)からファイルを取り出す

Posted at

実現したいこと

gitコマンドで特定のコミット(リビジョン)から特定のファイルを取り出す

実現方法および解決方法

git コマンドのshow オプションを利用する

実行コマンド

git show リビジョン番号:対象ファイル(相対パス)

実行例

$ git log | grep 'commit '
commit 181dcf1abaed2fb9f517c5c2352a73ef7f315e14
commit 7e048310984881f31a856252d9dccaecfa9bbf0b
$
$
$ git show 7e048310984881f31a856252d9dccaecfa9bbf0b:hoge/body.txt
123 ba1f2511fc30423bdbb183fe33f3dd0f
456 d2d362cdc6579390f1c0617d74a7913d
789 aa3f5bb8c988fa9b75a1cdb1dc4d93fc
000 23ebe88c0224f4f4fc0b608216e98735
111 1181c1834012245d785120e3505ed169

$
  • ファイルに書き出す場合
$ git show 7e048310984881f31a856252d9dccaecfa9bbf0b:hoge/body.txt > ~/tmp/git-tmp/body.txt

情報源

補足

24
26
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
24
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?