简体   繁体   中英

How to get files from a commit, to a folder outside from my repository?

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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM