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

Has*_*ell 5 linux git email sendmail github

我有一个本地创建的目录: /home/Tegra.

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

hello_world.c hello_world_1.c hello_world_2.c
Run Code Online (Sandbox Code Playgroud)

每个文件都是逐步修改的.我还创建了补丁:

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
Run Code Online (Sandbox Code Playgroud)
  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
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Cannot run git format-patch from outside a repository
Run Code Online (Sandbox Code Playgroud)

存储库在哪里出现.我应该首先维护我的代码库.

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

  1. 在Github上创建了一个空存储库:"MyRepo"
  2. 克隆在本地机器上.(使用git clone)
  3. 然后将第一个文件"hello_world.c"添加到Directory/MyRepo中.
  4. 然后>> git add hello_world.c
  5. 然后>> git commit -m'我的第一个来源'
  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
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 2

然后将第一个文件“hello_world.c”添加到目录“/MyRepo”中。

首先确保您实际上已在克隆的空存储库中提交了任何内容。

git add .
git commit -m "new commit"
git push
Run Code Online (Sandbox Code Playgroud)

其次,该git send-email文档确实提到:

--subject=<string>
Run Code Online (Sandbox Code Playgroud)

指定电子邮件线程的初始主题。仅当也设置时才需要--compose

请务必使用--compose.

此格式期望文件的第一行包含“ ”值,第二行包含消息的Cc:“ ”。Subject:

这适用于 a .patch,而不是源本身。有关更完整的示例,
请参阅git format-patch和“如何使用 git-send-email 发送补丁”:

对于最后一次提交:

git send-email -1  --to=abc@xyz.org --subject="[asdasdas] assd asdasd"
Run Code Online (Sandbox Code Playgroud)

第三,更简单的解决方案是使用git bundle. 这会生成一个文件,您可以以任何您想要的方式发送该文件,并且接收者可以从中提取/克隆。它(那个文件)充当一个裸 git 存储库。