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.
To go back to a specific commit use git reset YOURSHA. The reset command resets your current HEAD to a specific commit, without creating a new commit for the revert. You need to replace YOURSHA with the SHA of the commit you want to revert to. You can find the SHA with git log. With no additional flags the reverted changes are kept.
To checkout the specific commit, we need the SHA1 identifier as shown in the git log command. For example, suppose we need to checkout the commit “8e2e9aa71ca94b74a9d9048841d95d408ff7db3b”, we can use the command:
Use git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id>. Don’t forget the final ‘.’
The git add command is used to move changes to the working files, along with any new files, to the staging area. At this point, the working directory and the staging area are in sync, but the changes are still not in the local repository. When the changes are complete, developers can use git commit to move their changes to their repository.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With