Git Sparse Checkout 在工作目录中没有任何条目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24691300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:17:35  来源:igfitidea点击:

Git Sparse Checkout Leaves No Entry on Working Directory

gitbitbucket

提问by henry000dev

I am trying to use sparse-checkout to just check-out a directory from a BitBucket repository, but getting a "Sparse checkout leaves no entry on working directory" error when I try to pull.

我正在尝试使用 sparse-checkout 来从 BitBucket 存储库中检出一个目录,但是当我尝试拉取时,出现“稀疏结帐不会在工作目录上留下任何条目”错误。

The BitBucket repository has the following directory structure:

BitBucket 存储库具有以下目录结构:

  • SomeProjectRepo
    • JohnsProject
    • MarysProject
    • MyProject
  • SomeProjectRepo
    • 约翰计划
    • 玛丽斯计划
    • 我的项目

I have a local directory on E:\Temp\SomeProjectRepo on my Windows 7 laptop. I want to just checkout/pull "MyProject" from the BitBucket repository to my local directory, so I can just work on E:\Temp\SomeProjectRepo\MyProject.

我在 Windows 7 笔记本电脑上的 E:\Temp\SomeProjectRepo 上有一个本地目录。我只想从 BitBucket 存储库中检出/拉取“MyProject”到我的本地目录,这样我就可以在 E:\Temp\SomeProjectRepo\MyProject 上工作。

So I created "E:\Temp\SomeProjectRepo" and did the following in DOS:

所以我创建了 "E:\Temp\SomeProjectRepo" 并在 DOS 中执行以下操作:

  1. cd E:\Temp\SomeProjectRepo
  2. git remote add origin https://bitbucket.org/blah/blah
  3. git init
  4. git config core.sparsecheckout true
  5. echo MyProject > .git/info/sparse-checkout
  6. git pull origin master
  1. cd E:\Temp\SomeProjectRepo
  2. git remote add origin https://bitbucket.org/blah/blah
  3. git init
  4. git config core.sparsecheckout true
  5. echo MyProject > .git/info/sparse-checkout
  6. git pull origin master

At step 6, I get the "Sparse checkout leaves no entry on working directory". I have tried different syntax in step 5 (e.g. MyProject\, SomeProjectRepo\*, SomeProjectRepo\MyProject\, etc, etc) but none worked.

在第 6 步,我得到“稀疏结帐在工作目录上没有任何条目”。我曾试图在第5步(如不同的语法MyProject\SomeProjectRepo\*SomeProjectRepo\MyProject\,等,等),但没有奏效。

How do I use sparse-checkout (or any other tools) to only work on "MyProject"?

我如何使用 sparse-checkout(或任何其他工具)只处理“ MyProject”?

回答by henry000dev

OK, I got this working. As I expected it was not working because of step 5.

好的,我开始工作了。正如我所料,由于第 5 步,它不起作用。

The line below works now:

下面的行现在有效:

echo "MyProject/*"> .git/info/sparse-checkout

The important thing is to use /, use *and leave no space at the end of the directory.

重要的是使用/,使用*并且在目录末尾不留空格。

Then you may pull again or checkout the branch (git checkout master).

然后您可以再次拉取或检出分支 ( git checkout master)。

回答by Willem

On Windows, the echo "..." > outfilecommand creates a file in default system encoding. Git cannot deal with that, it requires the file to be in ASCII.

在 Windows 上,该echo "..." > outfile命令以默认系统编码创建文件。Git 无法处理,它要求文件为 ASCII。

Powershell solution:

Powershell 解决方案:

Set-Content .git\info\sparse-checkout "MyProject/*" -Encoding Ascii

or

或者

echo MyProject/* | out-file -encoding ascii .git/info/sparse-checkout

See the longer explanation here On Windows git: “error: Sparse checkout leaves no entry on the working directory”

在 Windows git 上查看更长的解释:“错误:稀疏结帐在工作目录上没有任何条目”

回答by Justin Grote

Windows Git 2.25 Note

Windows Git 2.25 注意

2.25 includes the git sparse-checkoutfeature to frontend some of this work. However, as far as i can tell it writes to the sparse-checkout file as UTF8, which is the same problem noted by Willem

2.25 包括git sparse-checkout前端一些这项工作的功能。但是,据我所知,它以 UTF8 格式写入稀疏结帐文件,这与 Willem 指出的问题相同

I used the powershell solution in this thread to force ascii https://stackoverflow.com/a/55158885/12927399

我在这个线程中使用了 powershell 解决方案来强制 ascii https://stackoverflow.com/a/55158885/12927399

Just providing a gotcha warning for git sparse-checkoutcommand!

只是为git sparse-checkout命令提供一个陷阱警告!

回答by arfa

if you are working on windows the same as me

如果你和我一样在 windows 上工作

you shouldn't get the quotes in the sparse-checkout file, and it will not work and need to use /* at the end of the path

你不应该在 sparse-checkout 文件中得到引号,它不会工作,需要在路径的末尾使用 /*

this works for me

这对我有用

echo src/* >> .git/info/sparse-checkout

echo src/* >> .git/info/sparse-checkout