blu*_*oot 174 git directory pull
我有一个带git的项目,我只想克隆或拉出一个特定的目录,就像myproject/javascript一样,就像subversion一样.
进行一些更改,提交并再次推回.
这是可能的?
ver*_*hon 189
git fetch
git checkout HEAD path/to/your/dir/or/file
path/...
"()中的" .../file
"从包含" " 的repo根目录正下方的目录开始小智 89
在一个空目录中:
git init
git remote add [REMOTE_NAME] [GIT_URL]
git fetch REMOTE_NAME
git checkout REMOTE_NAME/BRANCH -- path/to/directory
Run Code Online (Sandbox Code Playgroud)
msb*_*msb 30
经过多次寻找答案,没有找到,放弃,再次尝试等等,我终于在另一个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
Run Code Online (Sandbox Code Playgroud)
为了做OP想要的(仅在一个目录上工作),只需.git/info/sparse-checkout
在执行上述步骤时添加一个目录.
非常感谢@cforbish!
fer*_*llo 19
如果您想在不输入目录的情况下获取目录中的最新更改,您可以执行以下操作:
$ git -C <Path to directory> pull
Run Code Online (Sandbox Code Playgroud)
shi*_*ara 13
这是不可能的.您需要拉动所有存储库或什么都不需
小智 9
也许这个命令可能会有所帮助:
git archive --remote=MyRemoteGitRepo --format=tar BranchName_or_commit path/to/your/dir/or/file > files.tar
Run Code Online (Sandbox Code Playgroud)
"Etvoilà"
git clone --filter
从 git 2.19 现在在 GitHub 上工作(测试 2020-09-18,git 2.25.1)
我不确定拉/取,但至少对于初始克隆,此选项与远程协议的更新一起添加,它确实阻止了从服务器下载对象。
例如,仅克隆d1
此存储库所需的对象:https : //github.com/cirosantilli/test-git-partial-clone我可以这样做:
git clone \
--depth 1 \
--filter=blob:none \
--no-checkout \
https://github.com/cirosantilli/test-git-partial-clone \
;
cd test-git-partial-clone
git checkout master -- d1
Run Code Online (Sandbox Code Playgroud)
我在以下位置更详细地介绍了这一点:Git:如何仅克隆 Git 存储库的子目录?
很可能git clone
在那个领域实施的任何东西也有git pull
类似物,但我还不能很容易地找到它。
小智 6
尝试并测试了这个作品!
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>
Run Code Online (Sandbox Code Playgroud)
希望这有帮助!
归档时间: |
|
查看次数: |
234544 次 |
最近记录: |