Commits in a git bundle
Asked Answered
C

2

11

Hy!

Is there a way to get a list of all commits stored in a git bundle without cloning it first?

Getting the heads is easy, but I couldn't find a way to get a full log out of it.

Conan answered 22/1, 2013 at 14:30 Comment(4)
Before I merge the bundle int the repository, I would like to check where the bundle stands (compared to the repo). Wether its head is already present in the repo or the other way round.Conan
maybe in that case it would be easier to add the bundle as a remote?Polonaise
Thanks for the tip. I will lokk into it, and try to find out the neccesary commandsConan
And for git-related experiments like this, do it into a clone you can rm -rf when done, they're cheap. git clone -ns /path/to/mine /path/to/temp makes about the cheapest possible temp clone, a few hundred KB tops, but it's definitely a temp clone unless you understand that s option. Anyway, make that, fetch the bundle into it as araqnid said, and you're golden. I don't like the bare clones araqnid mentioned for this, often enough I want to dink around and break things that require a checkout.Shroyer
P
8

It's not possible without writing some specialised software to walk through the pack included in the bundle. If the bundle was created with negative refs, it's possible that it will include deltas that are not resolvable using only objects in the bundle (the pack embedded in the bundle can be thin).

Cloning the bundle (at least to a bare clone) will split out the refs and and index the pack, producing a format that standard git commands can work with, so it's the simplest way (in terms of integration effort) to read it.

One thing you can do to "preview" a bundle before merging it in is to simply add it as a remote repo, and then you can fetch from it and access the tracking refs. So something like:

git remote add bundle /path/to/bundle
git remote update bundle

and now you can do gitk master...bundle/master etc. to compare branches in the bundle compared to your local repo, and finally git pull bundle master to merge it in.

Once you're done, simply clean up with git remote rm bundle

Polonaise answered 22/1, 2013 at 15:32 Comment(2)
Do you know if there is some way to simulate a merge (e.g. say what would happen without acutally calling the command). merge and pull do not have a --dry-run option.Conan
they don't, and there isn't. you can just do a merge and then abort by resetting to where you were before (git reset --hard HEAD if you're left with conflicts, git reset --hard HEAD@{1} if the auto-merge was successful)Polonaise
G
1

Fetching from the bundle, as suggested in araqnid's answer, remains the easiest solution.

Anything else (meaning without cloning/fetching from the bundle) would involve decoding the git bundle format.
Which is slightly easier to do with Git 2.25.1 (Feb. 2020), since the technical details of the bundle format have been documented.

See commit 7378ec9 (07 Feb 2020) by Masaya Suzuki (draftcode).
(Merged by Junio C Hamano -- gitster -- in commit e99c325, 12 Feb 2020)
See discussion.

doc: describe Git bundle format

Signed-off-by: Masaya Suzuki

The bundle format was not documented. Describe the format with ABNF and explain the meaning of each part.

(ABNF: Augmented Backus–Naur form, a metalanguage based on Backus–Naur form (BNF), but consisting of its own syntax and derivation rule)

See Documentation/technical/bundle-format.txt for more:

bundle    = signature *prerequisite *reference LF pack
signature = "# v2 git bundle" LF

prerequisite = "-" obj-id SP comment LF
comment      = *CHAR
reference    = obj-id SP refname LF

pack         = ... ; packfile
Gans answered 13/2, 2020 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.