我需要 git diff
功能来处理我在任何存储库之外的 2 个文件。有办法吗?像 git diff --file1/path/file1.txt --file2/path/file2.txt
如果不是,可能有什么替代解决方案?
最佳答案
答案就在the git diff
documentation (虽然我承认很容易错过):
git diff [<options>] --no-index [--] <path> <path>
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.
您的案例可能属于“--no-index
is optional”类别,但即使它是可选的,您仍然可以使用它,因此:
git diff --no-index /path/file1.txt /path/file2.txt
将使用 Git 的 diff。
关于任何存储库之外的自定义 2 文件的 git diff?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50889139/