-1

I'm slightly confused regarding how Git handles initial git clone of a remote repository. I need to retrieve a full Git patch (diff) for all commits across all branches for a given <repo> URI.

Currently I'm doing the following:

$ git clone <repo>
$ git rev-list --all | xargs git show

Then my concern: does Git get all repository data in its index (including all commits from all branches) or does it get full history only for a master branch?

In other words, my question: whether git clone alone is sufficient to get the "full" patch/diff I need?

UPDATE: <repo> may have a couple of orphan branches

ddnomad
  • 373
  • 3
  • 15

2 Answers2

0

git clone is supposed to copy the entire repository with all the branches.

Try cloning it, and then run git branch -a. It should list all the branches.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Well, my main concern was whether cloning actually fetches all changes from an initial commit across all branches. List of remote branches is not a confirmation per se. Though right now I’m almost certain it does so (thanks to https://stackoverflow.com/questions/16427600/how-git-clone-actually-works). Nevertheless I’d strongly appreciate a link to a relevant piece of documentation which states that explicitly. – ddnomad Sep 05 '18 at 12:41
  • 2
    @ddnomad : Actually, the list of remote branches *is* pretty good confirmation, because git cannot store a ref without storing (at least part of) the corresponding history. It is possible to have a shallow history of a ref - in which case the last commit shown in that ref's history would have a parent entry. But if you didn't specifically request a shallow history, then this would only happen if the history in the remote were already shallow. – Mark Adelsberger Sep 05 '18 at 12:59
0

Update - In comments on another answer, you requested documentation of git's behavior. That would be the git clone docs (https://git-scm.com/docs/git-clone). If that's what you were actually asking for, you should've said so in your question instead of burying the real ask in a comment. That said, bear in mind that requests for documentation are off-topic and if you need git docs, they're all pretty easy to find by googling the relevant command.


does Git get all repository data in its index (including all commits from all branches) or does it get full history only for a master branch?

Well...

As for what you're trying to ask, by default clone copies the full history of all branches. You can limit this behavior with options like single-branch or depth, but copying everything is the default.

However, your terminology is a bit of a problem. The index is usually a single snapshot of the project, representing the content as it would be recorded by git commit. (The exception is during merging, when it may store multiple states of files that are in conflict.) It is not where history is stored, and it is not what rev-list consults.

So git does not "get all repository data in its index"; it gets the data in the local database.

Also, there may be additional information, beyond the histories of all branches, that is not fetched by default. But if the question is just about branches and their histories, then yes, everything is fetched.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • Do appreciate your terminology remarks. Is there any more or less concise documentation (or other resource) where I can get a grasp on details? – ddnomad Sep 05 '18 at 12:59
  • https://git-scm.com/docs/git-clone -- this one is rather CLI options and just a little regarding inner workings. But thanks anyway, I'll try to find some docs on "local database" of Git myself. – ddnomad Sep 05 '18 at 13:07
  • @ddnomad - The documentation you had requested at the time I wrote that update was regarding what is fetched by clone, so that's what I provided. I am not aware of a "concise" document of git's inner workings, as that's a rather broad topic. – Mark Adelsberger Sep 05 '18 at 13:51