In Git, SHA-1 hashes are used to identify objects. What exactly does a SHA-1 hash uniquely identify?
Think about what Git uses to detect changes and avoid duplicates.
Git uses SHA-1 hashes to uniquely identify the content of files, commits, trees, and other objects. This ensures that if the content changes, the hash changes, helping Git track changes and maintain integrity.
What is the output of the following command if the file example.txt contains the text Hello?
git hash-object example.txt
Check the SHA-1 hash of the string 'Hello' without newline.
The SHA-1 hash of the string 'Hello' (without newline) is aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d. The command git hash-object outputs this hash for the file content.
You have two files with exactly the same content, but git hash-object shows different SHA-1 hashes for each. What could cause this?
Think about invisible characters that affect file content.
Different line endings (Windows CRLF vs Unix LF) change the actual bytes in the file, causing different SHA-1 hashes even if the visible text looks the same.
Arrange the steps Git follows when creating a commit object and calculating its SHA-1 hash.
Think about how Git builds from directory snapshot to commit storage.
Git first creates a tree object for the directory, then a commit object referencing that tree and parents. It then calculates the SHA-1 hash of the commit content and stores the commit object named by that hash.
SHA-1 hashing is known to have vulnerabilities. Why is this a concern for Git, and what approach has Git taken to address it?
Consider cryptographic weaknesses and Git's recent updates.
SHA-1 has known collision vulnerabilities that could allow attackers to create fake commits with the same hash. Git is gradually moving to SHA-256, a stronger hash algorithm, to improve security.