如何从两个文件创建 git 补丁?

How to create git patch from two files?

我是 git 的新手,我只是想知道是否可以从两个不同的文件创建一个 git 补丁。没有 git 存储库,场景是我有一个文件并且我修改了它,现在我想创建一个补丁来区分这两个文件。任何指针?或者我应该继续创建一个 repo,然后修改文件,然后提交更改?

查看 git diff man page,您可以尝试使用:

git diff --no-index --patch 

有:

git diff --no-index [--options] [--] [<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.

开始于:

  • --补丁是默认选项
  • 当 运行 由 Git
  • 控制的工作树之外的命令时,您可以省略 --no-index

您应该可以在 git 存储库之外使用 git diff 而不会出现任何问题。