How does git know the sha1 name of the pack files?

Hypothetical situation:
I have a git repository, I have the index, HEAD, refs, packed-refs etc.
I don’t know the names of the pack files in .git/objects/pack

How does git figure out the name of the pack files? Is there a way to calculate the name of the pack files from the index file?

  • Git rebase fails with conflicts, but there are no conflicts
  • Merging a git stash with the current head
  • How to make compiling of Swift file in Xcode optional?
  • how to add files/folders to gitignore in intellij GUI?
  • Better control of git log formatting
  • How do I use git to checkout just the files and their parent folders that have a given file extension?
  • Update:
    .git/objects/info/packs is the closest I’m gonna get to what I’m looking for. This file is not always present though.

  • git - two branches named the same? Difference is one lower case - one mixed case?
  • Git: how to find out real changed files in a merge commit?
  • git, how to I go back to origin master after pulling a branch
  • Git cannot undo modified files
  • How to make Git “forget” about a file that was tracked but is now in .gitignore?
  • cygwin git thinks that file previously had different mode
  • One Solution collect form web for “How does git know the sha1 name of the pack files?”

    As a general rule, git just reads the contents of the objects/pack directory: it does not know a priori what the pack file SHA-1 values will be. However, when it goes to make a new pack file, it does calculate an SHA-1 and use that for the name of the pack file; and the name of the index is necessarily the same as the name of the pack-file, so if

    objects/pack/pack-1713881825f0238230418a7f843a8c9af9b70eea.pack
    

    exists, then

    objects/pack/pack-1713881825f0238230418a7f843a8c9af9b70eea.idx
    

    should also exist, for instance (these names found by looking in a directory, there’s no particular significance to these SHA-1s).

    There may also be .keep and .bitmap files corresponding to any given SHA-1 (bitmaps appear to be new in git 2.0.0).

    For more amusing enlightenment on pack files, see

    Documentation/technical/pack-heuristics.txt
    

    in the git source. 🙂

    Git Baby is a git and github fan, let's start git clone.