在Windows上git:“错误:稀疏结帐在工作目录上没有条目” [英] On Windows git: “error: Sparse checkout leaves no entry on the working directory”
问题描述
我有错误:
错误:稀疏结帐在工作目录中没有条目
当试图在git上设置一个稀疏结帐窗口时。在研究这个问题后,我已经回答了我自己的问题,并在网上发现了完整的答案。
在你想要源代码的文件夹中,使用git-bash提示NOT powershell (尽管见下面的编辑):
git clone -n< repo> <局部-目录名称>
cd< local-directory-name>
git config core.sparsecheckout true
echo some / sub-folder / you / want>> .git / info / sparse-checkout
git checkout< branch-name>
完整说明
稀疏结帐可让您处理存储库的一个子集。这是值得的努力设置稀疏签出大型仓库,一切都快得多!
我努力在Windows上设置它得到很多错误:稀疏结帐在工作目录上不留下任何条目。经过一番研究,我发现以下步骤非常简单,对我来说一直有很好的结果 - YMMV。
最重要的一点是 - 不要使用POWERSHELL / CMD进行这些步骤 - 使用git bash提示符。这是因为否则echo命令会生成一个带有BOM标记的UNICODE文件。这个文件必须是ANSI格式的文件,UNIX风格的行结尾才能让git正确解析它。这是导致错误:稀疏结帐在工作目录上没有条目错误的最可能原因。-
假设文件夹名称为src执行以下操作,这将抓取整个回购(仍然需要),但重要的是不会执行结帐,并且正确设置原点远程和分支跟踪。
git clone -n< your repository> src
-
你应该有一个相当空的src文件夹(它将隐藏.git文件夹)。现在运行以下。这会更新本地git配置以启用稀疏检出,并在.git / info隐藏文件夹中创建一个文件,该文件将列出您在执行稀疏检出时要包括的所有文件夹。这可以稍后编辑以添加其他文件夹。 重要:确保在下面使用git bash提示符,并使用支持unix行结束约定的编辑器,并在编辑稀疏检出文件时另存为ANSI,否则您可能会收到error:稀疏结账不会在工作目录中出现错误错误。
<您要签出的路径>
可能如下所示:path / to / subfolder
- 注意缺少cd src
git config core.sparsecheckout true
echo<路径您要结帐> >> .git / info / sparse-checkout
-
现在您已准备好结帐。这应该只填充稀疏检出文件夹。如果没有,请仔细检查以上所有内容的拼写!
git checkout< branch-name>
编辑 - Powershell中的回声
我最近发现powershell中的echo是写输出的synomym。可以通过将echo输出到 out-file
命令来获取ASCII输出,该命令允许您指定编码。因此,这将从Powershell工作,并提供正确的文件内容:
echo some / sub / folder / you / want | out-file -encoding ascii .git / info / sparse-checkout
I had the error:
"error: Sparse checkout leaves no entry on the working directory"
when trying to set up a sparse checkout in git on windows. I've answered my own question after researching the issue and finding the full answer spread out across the web.
tl;dr
From the folder in which you want the source to live, using a git-bash prompt NOT powershell (although see my edit below):
git clone –n <repo> <local-directory-name>
cd <local-directory-name>
git config core.sparsecheckout true
echo some/sub-folder/you/want >> .git/info/sparse-checkout
git checkout <branch-name>
Full explanation
Sparse checkouts enable you to work on a subset of the repository. It’s worth the effort to set up sparse checkouts on large repositories, everything is much faster!
I struggled with setting it up on windows getting a lot of "error: Sparse checkout leaves no entry on the working directory". After a bit of research, I found the following steps were minimal and had consistently good results for me – YMMV.
The most important point is this – DO NOT USE POWERSHELL/CMD FOR THESE STEPS – use a git bash prompt. This is because otherwise the echo command produces a UNICODE file with a BOM marker. The file MUST be an ANSI formatted file with UNIX style line endings for git to parse it correctly. This is the most likely cause of "error: Sparse checkout leaves no entry on the working directory" errors.
From a parent of the directory you wish to be the root folder, assuming a folder name of "src" do the following, This grabs the whole repo (which is still required), but does importantly does not perform a checkout, and correctly sets up the origin remote and branch tracking.
git clone –n <your repository> src
You should have a fairly empty looking src folder (it will have the .git hidden folder). Now run the following. This updates the local git config to turn on sparse checkouts, and creates a file in the .git/info hidden folder that will list all the folders you want to include when doing a sparse checkout. This can be edited later to add other folders. Important: Be sure to use a git bash prompt for the below, and use an editor supporting unix line-ending conventions and save as ANSI when editing the sparse-checkout file, or you may get "error: Sparse checkout leaves no entry on the working directory" errors. The
<path you want to checkout>
might look like this:path/to/subfolder
- note the lack of leading and trailing path separators.cd src git config core.sparsecheckout true echo <path you want to checkout> >> .git/info/sparse-checkout
Now you are ready to checkout. This should leave just the sparse-checkout folders populated. If it doesn’t, carefully check your spelling of everything above!
git checkout <branch-name>
Edit - Echo in Powershell
I recently discovered that echo in powershell is a synomym for write-output. It's possible to get ASCII output by piping the echo to the out-file
command which allows you to specify an encoding. So this will work from Powershell and give the correct file contents:
echo some/sub/folder/you/want | out-file -encoding ascii .git/info/sparse-checkout
这篇关于在Windows上git:“错误:稀疏结帐在工作目录上没有条目”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!