Shallow clone cannot fetch new commits/branches?

后端 未结 4 2017
南笙
南笙 2021-01-29 07:36

I have this:

git clone --depth=1  app
cd app
git fetch origin
git checkout a119b1076dd45a88a3609c4f7893ef3d82f9a4ee

but it says:

相关标签:
4条回答
  • 2021-01-29 08:10

    When you're doing a shallow clone you may want to specify a branch you are going to fetch:

    git clone --depth=1 --branch=me/work <repo> app
    
    0 讨论(0)
  • 2021-01-29 08:15

    I think this way works if you do a shallow clone

    git fetch origin me/work
    git checkout -b temp FETCH_HEAD
    
    0 讨论(0)
  • 2021-01-29 08:26

    A shallow clone is also, by default, a single-branch clone:

    --depth <depth>
    Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless ...

    A single-branch clone is just what it says: a clone that copies only one branch from the upstream. (The underlying mechanism is via the default fetch refspecs, so you can temporarily override this for one fetch by supplying refspecs.)

    If you want a shallow clone to copy more than one branch, you must convert it to a non-single-branch clone, or start it out as a non-single-branch clone. To start out as one, keep reading the rest of the quoted sentence. To change an existing single-branch clone to a two, three, or all-branch clone, see How do I "undo" a --single-branch clone?

    0 讨论(0)
  • As the docs for --depth says,

    Implies --single-branch unless --no-single-branch is given

    so if you want

    to fetch the histories near the tips of all branches

    give --no-single-branch on your clone, or for one-off correction do the fetch yourself,

    git fetch --depth=1 origin +refs/heads/*:refs/remotes/origin/*
    

    or to retroactively shut off the single-branch setup

    git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
    

    and then git fetch.

    0 讨论(0)
提交回复
热议问题