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.

  • apparently same commits give different sha1, why?
  • Edit a commit message in the pushed code
  • git - Easier way to do a simple one-commit squash?
  • How to get top committers who make certain percentage of the commits?
  • What should be in a first commit?
  • Concatenate the history of two Git repositories?
  • Workaround git commit
  • what is the equivalent in TFS of git cherry-pick
  • Deploy a pre existing django git repo to heroku
  • How to avoid PhpStorm staging file on Refactor > Rename
  • Why did git svn remote tracking stopped working?
  • How to undo last commit
  • 2 Solutions collect form web for “Git: retrieve specific commit”

    To export the repository up to a certain commit:

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

    To create a patch between two commits:

    git diff COMMIT1 COMMIT2 > patch.txt

    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.

    Git Baby is a git and github fan, let's start git clone.