2

I created a git repo and I want the entire git repo with all commits as a single patch file.

I've tried many SO posts, but couldn't find any suitable solution anywhere.

Toby Allen
  • 10,672
  • 11
  • 72
  • 123
Palak Arora
  • 973
  • 1
  • 9
  • 16

3 Answers3

7

In order to create a single patch encapsulating the whole repository, you need to diff the current HEAD against the empty tree. Such a tree is available in git under the SHA1 4b825dc642cb6eb9a060e54bf8d69288fbee4904 (This is the SHA1 that you would get if you created the empty tree by emptying the index and issuing git write-tree. Every git repository has one.)

Therefore the command you are looking for is:

git diff --binary 4b825dc642cb6eb9a060e54bf8d69288fbee4904..HEAD

The --binary option makes sure that binary content will be included in the diff, and that the file names will not be abbreviated.

user4815162342
  • 124,516
  • 15
  • 228
  • 298
  • Seriously? downvoted *again*? Could we at least wait for the OP to clarify the exact use case? I will delete my answer if Palak confirms that diff was the right answer. – VonC Aug 25 '14 at 08:43
  • @VonC Why insist on providing an answer that doesn't answer the question? While the OP's wish to obtain a "single patch file" is admittedly strange, I don't see how either of your interpretations fits the term. You have been on SO far longer than me, and should know better than to scoff at an occasional downvote. (I won't even comment the practice of deleting an answer and then resubmitting the exact same one.) – user4815162342 Aug 25 '14 at 12:01
2

While user4815162342's answer is technically the right solution (upvoted), Palak Arora's question about "an entire git repo with all commits as a single patch file" could be interpreted differently.

Here are two other possibilities, pending Palak's feedback:


If by patch "with all commits" you mean the full history of a git repo as one file, you could consider creating a bundle.
It is a single file which acts actually as a Git repo: you can fetch or pull or clone from that file;

cd /path/to/your/repo
git bundle create /tmp/foo-all --all

If your "patch" is actually the full content of the current repo, you can also use git archive

cd /path/to/your/repo
git archive -o /tmp/foo.tar --format=tar .

In both cases, they differ from the classic patch in that you wouldn't use a bundle or an archive to "apply" that "patch" on an existing code base, but rather to rebuild quickly said code base from scratch.

Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
1

Since, I tried out another method on my own, I thought of posting it here. It was exactly what I needed.

git log --pretty=format:"%H - %an, %ad : %s" --author "<your name>" --after="2014-05-19 00:00:00" --before="2014-08-18 00:00:00" -p --no-merges > ~/<path to some folder>/myrepo.patch
Palak Arora
  • 973
  • 1
  • 9
  • 16