For shallow clones, you can use the --depth parameter, and for the branch,
well, --branch. For more fine grained options you should consult the
git-init manpage, which may present you other useful switches.

For the last N commit part: N can be any positive integer, including one.
This makes it possible to get an actual snapshot of the given branch. Which
leads directly to your other question.

Git stores a directory tree snapshot with every commit, and this directory
tree references files (blobs in Git terminology). Whenever you change a
file's contents the corresponding blob changes and with it, naturally, the
whole tree, and this new tree will be saved with your next commit.

Now if you don't change a file through 200 commits, that means the
corresponding blob reference in all your trees remains unchanged. Thus, you
will get the same blob (the file's contents) in the last commit as you did
200 commits before.

When you make a shallow clone, Git will fetch the tree of the last N
commits (N is what you specified after --depth), and all the referenced
blobs. However, as that old blob is referenced by both the old and new
trees, you don't have to fetch 200 commits, just the last few (N). (Note
that technically a bit different things happen in the background; but in
the end you will get only those last N commits.) For more information on
this subject, I suggest to read an article/book on Git's internals (like
[1]) and shallow clones (like [2]).

Best,
Gergely

[1] http://git-scm.com/book/en/v1/Git-Internals
[2]
http://strk.keybit.net/blog/2011/06/07/getting-just-the-tip-of-a-remote-git-branch/
On 25 Feb 2015 19:42, "Michael" <keybou...@gmail.com> wrote:

>
> On 2015-02-24, at 10:40 PM, Gergely Polonkai <gerg...@polonkai.eu> wrote:
>
> Hello,
>
> yes, basically that is the way. There is an option in recent Git called
> shallow clone, which doesn't clone the whole history, only the last N
> commits. You can also specify the branch name you want to use instead of
> master, so using these two, you will actually get what you want.
>
> Alright, so what is the actual syntax?
>
> Also: the last N commits? Not the current state of the branch? ...
>
> What if there's one file in the directory that has not been changed in two
> years -- would that mean fetching two years worth of history to retrieve
> the current state of things?
>
> ...
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Git for human beings" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to git-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to