5

I have a repo: hello.git. I'm able to perform a sparse checkout: sparse checkout path: /test/test1

Now I have this in my workspace:

.../workspace/test/test1/content

I want to have the following:

.../workspace/content

Is it possible to checkout only the content of the path you describe?

Martin
  • 3,960
  • 7
  • 43
  • 43
DenCowboy
  • 13,884
  • 38
  • 114
  • 210

1 Answers1

4

This is not possible in git.

When you checkout in sparse mode, git only updates entries matched by your configuration in $GIT_DIR/info/sparse-checkout (this is set by the Git plugin on Jenkins).

Git does not support changing the root of the working tree in checkout. So when you do a sparse checkout, you will always have the whole directory structure of the files you selected.

https://git-scm.com/docs/git-checkout

Martin
  • 3,960
  • 7
  • 43
  • 43
  • 1
    While I don't think it's possible in Jenkins, but to complete your answer: Technically it is possible to change the root of a working tree directly from git with `git filter-branch --subdirectory-filter `. Note: It happens after the checkout, and it is only possible when making read-only checkouts as the repo is no longer compatible with upstream. – Majki Jul 10 '17 at 13:35
  • Although I still don't think it's possible, it's worth mentioning the way Git can do this from version 2.19 on: https://stackoverflow.com/a/52269934/344480 – Matthias May 06 '20 at 07:13