Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: retrieve specific commit

Tags:

git

export

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.

like image 802
user1170896 Avatar asked Jan 26 '12 08:01

user1170896


People also ask

How to go back to a specific commit in Git?

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.

How to checkout specific commit in git log?

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:

How do I find the commit ID of a git branch?

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 ‘.’

What is the difference between GIT add and git commit?

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.


1 Answers

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

like image 197
tobiasbayer Avatar answered Nov 07 '22 07:11

tobiasbayer