我在本地创建了一个目录:/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
现在我想先使用 git send-email 向电子邮件地址 abc@xyz.org. 发送一封电子邮件,其中应包含 hello_world。 c文件
然后我想发送第二封电子邮件,附件是 hello_world_1.patch 文件。
然后我想发送第三封电子邮件,附件是 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 步:根据下面的评论,我们需要一个存储库:
- 在 Github 上创建了一个空的存储库:“MyRepo”
- 在本地机器上克隆它。 (使用 git clone )
- 然后将第一个文件“hello_world.c”添加到目录/MyRepo 中。
- 然后 >>git add hello_world.c
- 然后 >>git commit -m 'My First source'
- 然后 >>git push -u origin master
- 之后,我输入: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
, 以及“How to send patches with git-send-email ”以获得更完整的示例:
对于最后一次提交:
git send-email -1 --to=abc@xyz.org --subject="[asdasdas] assd asdasd"
第三,一个更简单的解决方案是 use git bundle
.这会生成一个 文件,您可以通过任何方式发送该文件,并且接收方可以从中提取/克隆该文件。它(那个文件)充当一个裸 git 仓库。
关于linux - 无法使用git send-email发送源码和补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016965/