Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
789 views
in Technique[技术] by (71.8m points)

git pull - Pulling just one directory out of a git repo

I have a git repo that I want to do a pull from. I do a normal git pull with no problems. The issue is that I want just one certain directory out of the repo. My thinking was that I could use a .gitignore file with a rule like this:

#Ignore all files
/
#Except the one I want
!/temp

The problem is this doesn't work. Is that the right way to do it or is there a better way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

git pull fetches and merges the remote branch.

.gitignore works only locally, and will hide matching entries from showing up on git status and being added to the index with git add. It's not what you want.

What you want to do, is fetch the remote branch, and from that, extract the dir/file you need.

$ git fetch <remote> <branch>
$ git checkout <remote>/<branch> -- relative/path/to/file/or/dir

the file/dir should now be in your branch and added to the index.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...