How to checkout from git
So far, being the only person on a project, I have been copying/pasting my project folders and renaming them (Ver1, Ver2, Ver3, etc.) as a version control scheme. Now I am trying to switch to Git.
This is what I did:
I initialized a.git
folder and added the first version to the Git repository.
Then I added all other versions as commits to the git repository and tagged them.
So now I have all the versions in the master branch and as tags.
My q开发者_运维技巧uestion is:
How can I (I do not know if checkout is the right word) grab any version from the Git repository and put it in an arbitrary folder without switching branches (or any other operation Git may think it has to do)? Just simply copying a version (any version) from Git to a folder without any connection between the Git repository and the folder?Usually you examine historical versions directly in your normal working tree (you can checkout any commit as a “detached HEAD”/“unnamed branch”) or indirectly view the history with with git log
(especially the -p
option), git blame
, et cetera.
But, if you really need to fully unpack an old version, you can use the git archive
command to create a tar archive of a particular commit1 (a tag name, a branch name (you will get its tip commit), or a commit object id (i.e. SHA-1 hash value) will work to specify a commit). You can easily pipe the archive into tar to extract it wherever you like.
From your repository directory:
git archive --format=tar branch-or-tag-name-or-commit-id |
(mkdir /path/to/destination && cd /path/to/destination && tar xf -)
git archive
will always work for local repositories. It can also be used with non-local repositories (or local repositories not based in your current working directory) via the --remote
option; not all Git hosting services may allow pulling archives (they may not want to spend the CPU time or bandwidth).
1
Actually, you can use use git archive
with any tree (i.e. the root directory or any subdirectory represented in any commit), but it is most commonly used with branch tips, tags, and commits.
do:
git clone (path to your repo)
or if you don't want the .git meta data do:
git archive (branch)
Your question was:
How can I (I do not know if checkout is the right word) grab any version from the GIT repository and put it in an arbitrary folder without switching branches (or any other operation GIT may think it has to do)?
You want to use the git checkout command:
git checkout myTag1.2.3
git checkout asdf81274982shjsks
git checkout origin/develop
The argument to checkout can be either a branch, a tag or a SHA1-hash.
You ALWAYS get the complete repository. You cant checkout parts of it. Remember that git stores snap shots of the complete repository.
精彩评论