git diff for custom 2 files outside of any repository?

前端 未结 2 1914
猫巷女王i
猫巷女王i 2021-01-26 19:33

I need git diff functionality for 2 files that I have outside of any repository. Is there a way to do it? Something like git diff --file1 /path/file1.txt --fi

2条回答
  •  失恋的感觉
    2021-01-26 20:13

    The answer is right in the git diff documentation (though I admit it's easy to miss):

    git diff [] --no-index [--]

      This form is to compare the given two paths on the filesystem. You can omit the --no-index option when running the command in a working tree controlled by Git and at least one of the paths points outside the working tree, or when running the command outside a working tree controlled by Git.

    Your case might fall into the "--no-index is optional" category, but even if it's optional you can still use it, so:

    git diff --no-index /path/file1.txt /path/file2.txt
    

    will use Git's diff.

提交回复
热议问题