What are the differences between git clone --shared and --reference?

前端 未结 3 1916
谎友^
谎友^ 2020-12-13 12:59

After reading the documentation, I still don\'t really understand what the differences are between --shared and --reference . They seem

3条回答
  •  难免孤独
    2020-12-13 13:49

    The link in the comments to your question is now dead.

    https://www.oreilly.com/library/view/git-pocket-guide/9781449327507/ch06.html has some great information on the subject. Here is some of what is there:

    first, we make a bare clone of the remote repository, to be shared locally as a reference repository (hence named “refrep”):
    $ git clone --bare http://foo/bar.git refrep

    Then, we clone the remote again, but this time giving refrep as a reference:
    $ git clone --reference refrep http://foo/bar.git

    The key difference between this and the --shared option is that you are still tracking the remote repository, not the refrep clone. When you pull, you still contact http://foo/, but you don’t need to wait for it to send any objects that are already stored locally in refrep; when you push, you are updating the branches and other refs of the foo repository directly.

    Of course, as soon as you and others start pushing new commits, the reference repository will become out of date, and you’ll start to lose some of the benefit. Periodically, you can run git fetch --all in refrep to pull in any new objects. A single reference repository can be a cache for the objects of any number of others; just add them as remotes in the reference:

    $ git remote add zeus http://olympus/zeus.git
    $ git fetch --all zeus

提交回复
热议问题