I have a project with git, and I just want to clone or pull a specific directory, like myproject/javascript just like subversion does.
make some changes, commit and push back again.
It's possible?
- cd into the top of your repo copy
git fetchgit checkout HEAD path/to/your/dir/or/fileWhere "
path/..." in (3) starts at the directory just below the repo root containing your ".../file"NOTE that instead of "HEAD", the hash code of a specific commit may be used, and then you will get the revision (file) or revisions (dir) specific to that commit.
In an empty directory:
git init
git remote add [REMOTE_NAME] [GIT_URL]
git fetch REMOTE_NAME
git checkout REMOTE_NAME/BRANCH -- path/to/directory
After much looking for an answer, not finding, giving up, trying again and so on, I finally found a solution to this in another SO thread:
How to git-pull all but one folder
To copy-paste what's there:
git init
git remote add -f origin <url>
git config core.sparsecheckout true
echo <dir1>/ >> .git/info/sparse-checkout
echo <dir2>/ >> .git/info/sparse-checkout
echo <dir3>/ >> .git/info/sparse-checkout
git pull origin master
To do what OP wants (work on only one dir), just add that one dir to .git/info/sparse-checkout, when doing the steps above.
Many many thanks to @cforbish !
It's not possible. You need pull all repository or nothing.
Maybe this command can be helpful :
git archive --remote=MyRemoteGitRepo --format=tar BranchName_or_commit path/to/your/dir/or/file > files.tar
"Et voilà"
git clone --filter from Git 2.19
This option will actually skip fetching unneeded objects from the server.
I have written a detailed answer explaining current support status at: How do I clone a subdirectory only of a Git repository?
It is very likely that whatever gets implemented for git clone in that area will also have git pull analogues.
Sometimes, you just want to have a look at previous copies of files without the rigmarole of going through the diffs.
In such a case, it's just as easy to make a clone of a repository and checkout the specific commit that you are interested in and have a look at the subdirectory in that cloned repository. Because everything is local you can just delete this clone when you are done.
来源:https://stackoverflow.com/questions/2425059/how-to-pull-specific-directory-with-git