Reputation: 13
I need to get the files from 2 commits(of my choice) and put in 2 diferent folders outside my repository, i'll do a process, and than i need to be able to erase those 2 folders after.
I aready try some commands,git -clone
doesn't work for me, i dont need the entire repository, just certain commits(one folder for each), and i have some inssues trying to erase the folder.
Other that i tried was git archive
but the output didnt work for me. I need the files in the same way as the repository.
The one who went pretty close was git --work-tree=<path> checkout <sha> -- .
but this command was stashing the files(who has diferences) on my repository, and i dont want that.
Is possible to do what i want, without making changes on my repository ?
Upvotes: 1
Views: 252
Reputation: 30888
git show <commit>:<file_path> > <path>
.
For example, git show HEAD:foo/bar.c > ~/build/foo/bar.c
, git show master:foo/bar.c > ~/backup/bar.c
.
git show
can be replaced with git cat-file -p
here.
If you want the whole repo, you could use git worktree
if you have a newer version. It just checkouts a revision to another folder instead of the current work tree, so you don't have to make another clone.
For example, git worktree add master ~/foo/
, which checkouts master
into ~/foo/
while the current work tree stays unchanged.
Upvotes: 0
Reputation: 38724
From your repository directory which is called project
:
mkdir ../foo && cd ../foo && echo 'gitdir: ../project/.git' >.git && git checkout <commit-ish> -- .
might produce the result you desire.
Upvotes: 2