我有一个项目与git,我只是想克隆或拉一个特定的目录,像myproject/javascript就像subversion一样。 做一些改变,提交并再次提交。 这是可能的吗?
当前回答
大多数答案/技术都会下载整个存储库,即使你只会看到/使用其中的一个子集。我不喜欢这样,因为我做的一些事情有很多我不感兴趣的大文件。在寻找答案,没有找到,放弃,再次尝试等等之后,我终于在另一个so线程中找到了一个解决方案:
如何拉出除了一个文件夹以外的所有文件夹
复制粘贴这里的内容:
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
要完成OP想要的(只处理一个目录),在执行上述步骤时,只需将该目录添加到.git/info/sparse-checkout。这个解决方案只会下载你想要的东西,仅此而已。
非常感谢@cforbish !
其他回答
也许这个命令会有帮助:
git archive --remote=MyRemoteGitRepo --format=tar BranchName_or_commit path/to/your/dir/or/file > files.tar
“就是这样”
这是不可能的。你需要调出所有的存储库。
对于我所做的理论文件路径和示例的所有斗争,这里有一个真实的例子: 微软在git hub上提供了他们的文档和示例,不幸的是,他们确实在这个存储库中收集了大量主题的所有示例文件:
https://github.com/microsoftarchive/msdn-code-gallery-community-s-z
我只对路径中的Microsoft Dynamics js文件感兴趣
msdn-code-gallery-community-s-z/Sdk.Soap.js/
所以我做了以下的事情
创建一个
msdn-code-gallery-community-s-zSdkSoapjs\.git\info\sparse-checkout
文件在我的存储库文件夹在磁盘上
git sparse-checkout init
在Windows下使用CMD在该目录中
的文件内容
msdn-code-gallery-community-s-zSdkSoapjs\.git\info\sparse-checkout
is
Sdk.Soap.js/*
最后做一个
git pull origin master
经过试验和测试,这是可行的!
mkdir <directory name> ; //Same directory name as the one you want to pull
cd <directory name>;
git remote add origin <GIT_URL>;
git checkout -b '<branch name>';
git config core.sparsecheckout true;
echo <directory name>/ >> .git/info/sparse-checkout;
git pull origin <pull branch name>
希望这对你有帮助!
如果你想在不进入目录的情况下获得目录的最新更改,你可以这样做:
$ git -C <Path to directory> pull