Search code examples
gitgit-branchgit-diff

git - How to checkout files from another branch based on diff-filter?


Let's say I want to checkout all the files from another branch that are missing from my current branch.

I know I can find these files by doing a git diff OTHER-BRANCH diff-filter=D because all files considered deleted are ones that my current branch is missing.

Is there a way to do a git checkout OTHER-BRANCH --diff-filter=D of some sort? Or perhaps you have to pipe all the files from the git diff into a git checkout?


Solution

  • git diff <BRANCH-NAME> --diff-filter=D --name-only --exit-code | xargs git checkout <BRANCH-NAME>
    

    Use the -0 flag (xargs -0) for complicated file names. It goes without saying that you should back up before testing new git commands.