LoginSignup
4
2

More than 3 years have passed since last update.

git で checkout せずに他のブランチのファイルを見たい

Last updated at Posted at 2019-11-29

git で、あるブランチ x で作業しているときに、他のブランチ y で追加されたファイル hoge.rb の内容を知りたくなった。そういうときにどうするか。
git show にブランチ名を与えると見ることができるらしい。リダイレクトすれば取り出す事もできる。

git show y:hoge.rb 
git show y:hoge.rb > file 

bat 使えばもっと見やすくできる

git show y:hoge.rb | bat -l ruby

Emacs では M-x magit-find-file の後にブランチ名、そしてパス付きのファイル名を与えれば同じことができる。
Refs モードなら、カーソルがあたっているところがデフォルトのブランチ名になる。

4
2
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
4
2