timhwang21.gitbook.io
  • Intro
  • Blog
    • 2023
    • 2022
    • 2021
    • 2020
    • 2019
  • CLI
    • Git
      • Bulk resolve merge conflicts
      • git rebase-onto
      • Patch from diff
    • Shell
      • Recipes
    • Vim
      • Batch editing
      • Buffers
      • <Ctrl-r>
      • External commands
      • :global
      • Help
      • Registers
      • Splits
    • Tools
  • Programming
    • React
      • Testing Styled Components
    • Typescript
      • curryRecord
      • Exhaustive conditionals with ADTs
      • newtype
      • OmitTypes
      • Safe JSON clone
      • Type inferrers
      • XOR type
    • Ruby
      • Pry
      • RSpec
    • Rails
      • Attributes
      • Cheap many to many
      • (Don't use) counter cache
    • Databases
      • Metrics
      • Testing indexes
  • Personal
    • Uses
    • Github
    • Medium
    • LinkedIn
    • Photography
Powered by GitBook
On this page
  • Diff certain files that have changed on a branch
  • Explanation
  • Tools used
  • Global file search interface
  1. CLI
  2. Shell

Recipes

PreviousShellNextVim

Last updated 3 years ago

Useful workflows that rely on a combination of tools.

Diff certain files that have changed on a branch

vim -c 'tabdo Gdiff origin/master' -p $(git diff --name-only origin/master | fzf)

. The above implementation diffs against the branch point instead of origin/master which results in a cleaner diff.

Explanation

When reviewing a feature branch, sometimes you want to know how one specific feature was impacted by the branch. For example, you want to see how every file in a certain directory or with a certain name was changed.

We open Vim with the command "for each tab (tabdo), diff the file against its version on master (Gdiff origin/master), and then we pass it the list of all files changed in the current branch (git diff --name-only origin/master), filtered using fzf."

What happens is that fzf's prompt opens up, letting you select a list of files using Tab. Upon completing your selection, all files will be diffed in splits in separate tabs, which you can navigate between using gt.

Tools used

  • vim-fugitive (specifically, :Gdiff)

  • fzf

Global file search interface

fd PATTERN | fzf is a good building block for building filterable commands.

vim `fd PATTERN | fzf`
cat `fd PATTERN | fzf`
# open parent folder of found file
open "`fd PATTERN | fzf`/.."
I've found this useful enough to add as a git alias