无法使用 git send-email 发送源代码和补丁

Unable to use git send-email to send source code and patches

我在本地创建了一个目录:/home/Tegra.

我在 /home/Tegra 中创建了以下文件:

hello_world.c hello_world_1.c hello_world_2.c

每个文件都是增量修改的。我还创建了补丁程序:

diff -u hello_world.c hello_world_1.c > hello_world_1.patch
diff -u hello_world_1.c hello_world_2.c > hello_world_2.patch
  1. 现在我想先使用 git send-email 发送一封电子邮件到电子邮件地址 abc@xyz.org. 应该包含 hello_world.c 文件

  2. 然后我想发送第二封电子邮件,附件是 hello_world_1.patch 文件。

  3. 然后我想发送第三封电子邮件,附件是 hello_world_2.patch 文件。

不幸的是,我什至无法完成第 1 步:

我的 git 已经正确配置了相关的 smtp 服务器 tls 587 端口。

我尝试了以下命令:

git send-email --to abc@xyz.org --subject My Hello hello_world.c

我收到以下错误:

Cannot run git format-patch from outside a repository

存储库在哪里出现。我是否必须首先维护我的代码存储库。

编辑:对于第 1 步:根据下面的评论,我们需要一个存储库:

  1. 在 Github 上创建了一个空存储库:"MyRepo"
  2. 在本地机器上克隆它。 (使用 git 克隆)
  3. 然后将第一个文件 "hello_world.c" 添加到目录 /MyRepo 中。
  4. 然后>>git添加hello_world.c
  5. 然后>>git commit -m 'My First source'
  6. 然后>>git push -u origin master
  7. 之后,我输入:git send-email --to=abc@xyz.org --subject="[asdasdas] assd asdasd" hello_world.c

现在我得到一个错误:

No subject line in hello_world.c ? at /usr/lib/git-core/git-send-email line 584

Then added the first file "hello_world.c" into the Directory /MyRepo".

首先确保您在克隆的空仓库中确实提交了任何内容。

git add .
git commit -m "new commit"
git push

其次,git send-email doc确实提到:

--subject=<string>

Specify the initial subject of the email thread. Only necessary if --compose is also set.

确保使用 --compose.

This format expects the first line of the file to contain the "Cc:" value and the "Subject:" of the message as the second line.

这将适用于 .patch,而不是源本身。
有关更完整的示例,请参阅 git format-patch, and "How to send patches with git-send-email":

最后一次提交:

git send-email -1  --to=abc@xyz.org --subject="[asdasdas] assd asdasd"

第三,更简单的解决方案是use git bundle。这会生成 一个 文件,您可以通过任何方式发送该文件,并且接收者可以从中 pull/clone 。它(那个文件)充当一个裸露的 git 仓库。