日記帳

プログラミングのことをつぶやく日記です。

Gitで管理しているプロジェクトで別のブランチから1ファイルだけ持ってくる

rebaseミスって、masterブランチから対象ファイルを持ってきたい時があるのでメモ

# まずはファイルが該当ブランチに存在するか確認する
git show <コピー元ブランチ名>:<ファイル名>
# 存在したら、今いるブランチへ適応させる
git checkout <コピー元ブランチ名> -- <ファイル名>

実際に使う時

git show master:hoge.rb
git checkout master -- hoge.rb

これ、実はhelpに書いてある。ちゃんとhelp読もうね。(戒め)

$ git show -h
usage: git log [<options>] [<revision-range>] [[--] <path>...]
   or: git show [<options>] <object>...

$ git checkout -h
usage: git checkout [<options>] <branch>
   or: git checkout [<options>] [<branch>] -- <file>...