5

I have a directory created locally: /home/Tegra.

I have created following Files inside /home/Tegra:

hello_world.c hello_world_1.c hello_world_2.c

Each file is incrementally modified. I have also created patches as:

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. Now I want to first send an email using git send-email to email address abc@xyz.org. which should contain hello_world.c file

  2. Then I want to send second email with hello_world_1.patch file as attachment.

  3. Then I want to send third email with hello_world_2.patch file as attachment.

Unfortunately, I am not even able to do the step 1:

My git has been properly configured with relevant smtp server tls 587 port.

I tried following command:

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

I get following error:

Cannot run git format-patch from outside a repository

Where does repository come into picture. SHould I have to maintain first a repository of my code.

Edit: For step 1: As per comments below we need a repository:

  1. Created a Empty Repository on Github : "MyRepo"
  2. Cloned it on local machine. (using git clone )
  3. Then added the first file "hello_world.c" into the Directory /MyRepo".
  4. Then >>git add hello_world.c
  5. Then >>git commit -m 'My First source'
  6. Then >>git push -u origin master
  7. After that, I typed: git send-email --to=abc@xyz.org --subject="[asdasdas] assd asdasd" hello_world.c

Now I get an Error:

No subject line in hello_world.c ? at /usr/lib/git-core/git-send-email line 584
parsley72
  • 8,449
  • 8
  • 65
  • 98
Haswell
  • 1,573
  • 1
  • 18
  • 45
  • 1
    Yes. send-email will create a patch from a change in your repository and send it. You need to point it to a git managed file or directory. – Andreas Wederbrand Oct 08 '15 at 13:20
  • Hi @AndreasWederbrand, I created a Empty Repository on Github : "MyRepo", cloned it on local machine, Then added the first file into the Directory "/MyRepo". After that, I typed: git send-email --to=abc@xyz.org --subject="[asdasdas] assd asdasd" hello_world.c Now I get an Error: No subject line in hello_world.c ? at /usr/lib/git-core/git-send-email line 584. – Haswell Oct 10 '15 at 04:42

1 Answers1

2

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

First make sure you have actually committed anything in your cloned empty repo.

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

Second, the git send-email doc does mention:

--subject=<string>

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

Make sure to use --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.

That would work with a .patch, not the source itself.
See git format-patch, and "How to send patches with git-send-email" for a more complete example:

For the last commit:

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

Third, a simpler solution would be to use git bundle. That generates one file that you can send any way you want, and from which the receiver can pull/clone from. It acts (that one file) as a bare git repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Then the http://status.bitbucket.org/git send-email -1` I mention should work. But `git bundle` is easier. – VonC Oct 11 '15 at 07:33
  • Yes I am able to send the email however the Subject Line is not what i entered in --subject , It changes to the line I used during git commit -m "line" – Haswell Oct 14 '15 at 04:43
  • Also a [Patch] gets added in the subject line. Will git bundle be able to solve this ? – Haswell Oct 14 '15 at 04:43
  • @Tegra what version of git are you using? – VonC Oct 14 '15 at 04:44
  • @Tegra a bundle is just one file, to be send however you want. – VonC Oct 14 '15 at 04:44
  • @Tegra it would be interesting to check if the issue persists with a more recent (2.6.1) git. – VonC Oct 14 '15 at 04:45
  • Yes same issue with git version 2.6.1 – Haswell Oct 14 '15 at 04:59
  • @Tegra I see in the doc https://git-scm.com/docs/git-send-email that `--subject` is "only necessary if `--compose` is also set". Maybe this is why it is ignored? – VonC Oct 14 '15 at 05:02
  • Also The first Email should contain the original source and then the next 2 emails should contain 2 patches on the original source. These emails should be linked. Is it also possible with git bundle. – Haswell Oct 14 '15 at 05:02
  • @Tegra git bundle is a compressed repo which included the commits you have specified. It is not a clear text file. – VonC Oct 14 '15 at 05:03
  • Yes!! My first git send-email is sent with correct Subject Line, the --compose was necessary for subject to be taken, as you pointed out. Now I just need to link the two patches with the First email. In that case should I commit the "hello_world_1.patch" into "MyRepo" or should I commit the new source File "hello_world_1.c" and directly send it through "git send-email". Will it create a patch from the updated source files ? – Haswell Oct 14 '15 at 05:08
  • @Tegra I believe that if you are using.patch files, you don't have to commit them. If you are using revision list, then the patches would be generated from those revision diff (so based on existing commits) – VonC Oct 14 '15 at 05:16