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.

  • Displaying a message to users pre-commit in Tortoise SVN
  • Not currently on any branch + git commit + checkout when not in any branch. Did i loose my changes?
  • Git Commits appear in Bitbucket but not in SourceTree
  • How to set git commit --author properly from rake running under LocalSystem account?
  • reverse back to certain commit and test what the issue?
  • git find fat commit
  • Can I use Git to apply update patches to customized software?
  • Remove file from the repository but keep it locally
  • Git check custom rules
  • Is there a maximum number of git stashes?
  • How to checkout a file into previous revision in egit
  • View two different files on two different branches in Xcode?
  • 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.