2

I have two people

  • Bob, which continues developing with its team on a project
  • Alice, which is now on holiday with her laptop far from Bob's office

Bob wants to send to Alice the diff of the master branch since Alice left.

I initially thought that

bob $ git format-patch --stdout e6def65..master > history.patch

alice $ git am history.patch

would preserve the commit hash, but it doesn't.

Is there a solution to easily exchange by e-mail a diff that preserves the commit SHA?

nowox
  • 25,978
  • 39
  • 143
  • 293
  • The commit hash is computed using the hash of the tree, the commit subject, the author email and date and the committer email and date. The committer email and date are different for Bob and Alice in your scenario. – axiac Aug 28 '17 at 14:46
  • `git am` *can* preserve commit hashes, but only if there are no merges (and by default it doesn't actually try to preserve hashes anyway—as @axiac noted you have to make the committer info match up). If you're the original author and committer and you make the time-stamps match (`--committer-date-is-author-date`), you will get the same hash, provided there are no merges. – torek Aug 28 '17 at 16:55

1 Answers1

5

Does git bundle do what you want?

Some workflows require that one or more branches of development on one machine be replicated on another machine, but the two machines cannot be directly connected, and therefore the interactive Git protocols (git, ssh, http) cannot be used. This command provides support for git fetch and git pull to operate by packaging objects and references in an archive at the originating machine, then importing those into another repository using git fetch and git pull after moving the archive by some means (e.g., by sneakernet). As no direct connection between the repositories exists, the user must specify a basis for the bundle that is held by the destination repository: the bundle assumes that all objects in the basis are already in the destination repository.

See also this previous question about Git over e-mail.

zoul
  • 102,279
  • 44
  • 260
  • 354