This repository contains two scripts, git_unreachable_objects_scraper.sh (Bash) and git_unreachable_objects_scraper.py (Python), designed to detect and display details about unreachable or dangling Git objects (specifically commits) in a Git repository. These scripts help identify commits that are no longer referenced by any branch, tag, or reflog, and provide detailed information such as commit metadata, diffs from parent commits, and associated file contents.
- Detects unreachable or dangling commits
- Displays commit metadata
- Shows the diff between the commit and its parent, if applicable
- Lists all files in the commit's tree and their blob SHAs
- Optionally displays the content of each file with the
-cor--contentflag - Recursively traverses the commit's tree to list all files
./git_unreachable_objects_scraper.sh [repository_path] [-c | --content]repository_path: Path to the Git repository (defaults to the current directory.).-c | --content: Optional flag to display the content of each file (blob) in the commit's tree.
# Scan the repository in the working directory
./git_unreachable_objects_scraper.sh
# Scan a specific repository
./git_unreachable_objects_scraper.sh /path/to/repo
# Scan and display file contents
./git_unreachable_objects_scraper.sh /path/to/repo --content- If no unreachable objects are found:
No unreachable Git objects found. - For each unreachable commit:
- Commit SHA and metadata (author, date, message).
- Diff from the parent commit (if available).
- List of files in the commit's tree with their blob SHAs.
- File contents (if
--contentis specified).
A script that performs the same functionality as the Bash script, but implemented using Python
- Similar to the Bash script, it detects unreachable or dangling commits
- Displays commit metadata, diffs from parent commits, and lists files in the commit's tree.
- Optionally shows file contents with the
-cor--contentflag. - Increased error handling compared to the Bash script
- Python 3.x
- Git installed and accessible from the command line.
python3 git_unreachable_objects_scraper.py [repository_path] [-c | --content]repository_path: Path to the Git repository (defaults to the current directory.).-c | --content: Optional flag to display the content of each file (blob) in the commit's tree.
# Scan the repository in the working directory
python3 git_unreachable_objects_scraper.py
# Scan a specific repository
python3 git_unreachable_objects_scraper.py /path/to/repo
# Scan and display file contents
python3 git_unreachable_objects_scraper.py /path/to/repo --content- Similar to the Bash script, it outputs:
- A message if no unreachable objects are found.
- For each unreachable commit: metadata, diff from parent (if available), list of files with blob SHAs, and file contents (if
--contentis specified).
- Both scripts require a valid Git repository at the specified path.
- Use the
--contentflag with caution, as it can produce large output if the commit contains many or large files. - Ensure you have sufficient permissions to access the repository and execute Git commands.