Linux command
git-hash-object 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Compute object hash
git hash-object [file]
Compute and store object
git hash-object -w [file]
Hash from stdin
echo "[content]" | git hash-object --stdin
Specify object type
git hash-object -t [blob] [file]
说明
git hash-object computes the SHA-1 object ID for a file and optionally stores it in the Git object database. This low-level plumbing command exposes Git's internal object storage mechanism. The command calculates the hash by formatting the file content as a Git object (with type and size header), then computing the SHA-1 hash. With the -w option, it also writes the object to .git/objects/, making it part of the repository even if not yet referenced by any commit. The --stdin option enables hashing content from pipes or scripts.
参数
- -w
- Write object to database.
- --stdin
- Read from stdin.
- -t _type_
- Object type (blob, commit, tree, tag).
- --path _path_
- Hash as if at path.
- --no-filters
- Don't apply filters.
FAQ
What is the git-hash-object command used for?
git hash-object computes the SHA-1 object ID for a file and optionally stores it in the Git object database. This low-level plumbing command exposes Git's internal object storage mechanism. The command calculates the hash by formatting the file content as a Git object (with type and size header), then computing the SHA-1 hash. With the -w option, it also writes the object to .git/objects/, making it part of the repository even if not yet referenced by any commit. The --stdin option enables hashing content from pipes or scripts.
How do I run a basic git-hash-object example?
Run `git hash-object [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -w do in git-hash-object?
Write object to database.