user1170896
user1170896

Reputation: 739

Git: retrieve specific commit

I need to export to an archive a set of commits in a git repository. How do I do this? Using svn, I could choose commits and export to zip.

Upvotes: 12

Views: 10714

Answers (2)

tobiasbayer
tobiasbayer

Reputation: 10379

To export the repository up to a certain commit:

git archive -o export.zip <COMMIT>. Replace <COMMIT> with the commit number you want to export.

To create a patch between two commits:

git diff COMMIT1 COMMIT2 > patch.txt

Upvotes: 19

Abizern
Abizern

Reputation: 150615

Git has a handy way of creating a patch for each commit. Although this originally was meant as a way to format patches so that they can be sent through email, they are a handy way of extracting a set of changes.

The command you want is git format-patch and the way you apply these formatted patches back into git is with the git am command.

For example if you you have two commits C1 and Cn that you want to export as a set of git patches you only need:

git format-patch -k C1..Cn

This will create a set of numbered patches (in your current directory). Each patch will be a diff of the commit, as well as the commit information (Title, comment, author, date, etc).

This is a lot more than a simple diff file between two commits will provide you.

Upvotes: 10

Related Questions