Quckie: git - copy a file from another branch without switching branch

Tag
Published:
Author: Ally

Ever wanted to grab a file from another branch in git, but don’t want to checkout to the target branch?

git-show to the rescue.

export BRANCH="123-feature"
export INPUT="app/Http/Livewire/MyComponent.php"
export OUTPUT="MyComponent-123-feature.php"
git show $BRANCH:$FILE > $OUTPUT

Or git-diff if you to do that:

git diff master:app/Http/Livewire/MyComponent.php \
  feature:app/Http/Livewire/MyComponent.php
Git image
Building an image for static site generator output
Laravel post migration event listener
To bottom
To top
< SM
max-width: 640px