quiltimport Git Command Guide
The git quiltimport command applies a quilt patchset onto the current Git branch, preserving patch boundaries, order, and descriptions. It converts quilt-managed patches into Git commits.
git quiltimport Syntax:
Section titled “git quiltimport Syntax:”git quiltimport [--dry-run | -n] [--author <author>] [--patches <dir>] [--series <file>] [--keep-non-patch]Import Options:
Section titled “Import Options:”| Option | Description |
|---|---|
-n, --dry-run | Check patches without applying |
--author <author> | Default author for patches |
--patches <dir> | Directory containing patches |
--series <file> | Series file path |
--keep-non-patch | Keep non-patch files |
Understanding Quilt Import:
Section titled “Understanding Quilt Import:”Quilt Patch Management:
Section titled “Quilt Patch Management:”Quilt Overview:├── Quilt is a patch management system for Linux kernel development├── Manages series of patches applied on top of source code├── Each patch represents one logical change├── Patches stored as individual .patch files├── Series file tracks patch order and application
Quilt Workflow:├── quilt new <patch-name> # Create new patch├── quilt add <files> # Add files to patch├── quilt edit <files> # Edit files in patch context├── quilt refresh # Update patch with changes├── quilt pop/push # Remove/apply patches└── quilt series # Show patch seriesGit Integration Process:
Section titled “Git Integration Process:”Quilt to Git Conversion:1. Analyze quilt series file for patch order2. Extract author information from patch descriptions3. Apply each patch as individual Git commit4. Preserve patch boundaries and descriptions5. Handle patch dependencies and conflicts6. Create Git commit history from patch series
Import Process:├── Read series file for patch ordering├── Validate patch files exist├── Extract metadata (author, subject, description)├── Apply patches in sequence├── Create commits with proper authorship└── Handle merge conflicts if they occurPatch Series Structure:
Section titled “Patch Series Structure:”Quilt Patch Series:├── patches/ # Directory containing .patch files├── series # File listing patches in order├── .pc/ # Quilt internal state (applied patches)└── [source code] # Modified source files
Series File Format:├── One patch filename per line├── Optional comments with #├── Patch options and metadata└── Maintains application order
Example series file:├── # Initial setup patches├── 001-initial-setup.patch├── 002-core-functionality.patch├── # Feature implementation├── 003-new-feature.patch└── 004-documentation.patchBasic Quilt Import Operations:
Section titled “Basic Quilt Import Operations:”Standard Import:
Section titled “Standard Import:”# Import quilt patches from default locationgit quiltimport
# Import from specific patches directorygit quiltimport --patches patches/
# Import with custom series filegit quiltimport --series my-series.txt
# Dry run to check patchesgit quiltimport --dry-runAuthor Handling:
Section titled “Author Handling:”# Specify default author for all patchesgit quiltimport --author "John Doe <john@example.com>"
# Interactive author entry (default when author missing)git quiltimport # Will prompt for missing authors
# Mixed approach - some specified, others interactivegit quiltimport --author "Default Author <default@example.com>"Advanced Import Scenarios:
Section titled “Advanced Import Scenarios:”# Import with non-patch files preservedgit quiltimport --keep-non-patch
# Import specific series filegit quiltimport --series patches/series.conf
# Combine optionsgit quiltimport --dry-run --author "Maintainer <maintainer@project.org>" --patches quilt-patches/Configuration and Best Practices:
Section titled “Configuration and Best Practices:”Git Configuration for Quilt Import:
Section titled “Git Configuration for Quilt Import:”# Configure quiltimport behaviorgit config quiltimport.defaultAuthor "Default Author <default@example.com>"
# Configure patch handlinggit config quiltimport.keepNonPatch false
# Configure series file locationgit config quiltimport.seriesFile "series"Safe Import Practices:
Section titled “Safe Import Practices:”# Always backup before importgit branch backup-before-quiltimport
# Test import firstgit quiltimport --dry-run
# Verify working tree is cleangit status
# Check patch validityfind patches/ -name "*.patch" -exec git apply --check {} \;
# Review imported commitsgit log --oneline -10Patch Preparation:
Section titled “Patch Preparation:”# Prepare quilt patches for importprepare_quilt_patches() { local quilt_dir="$1"
echo "Preparing quilt patches from $quilt_dir"
# Validate series file if [ ! -f "$quilt_dir/series" ]; then echo "Series file not found" return 1 fi
# Check patch files exist while read -r line; do # Skip comments and empty lines [[ "$line" =~ ^# ]] || [ -z "$line" ] && continue
patch_file="$quilt_dir/$(echo "$line" | awk '{print $1}')" if [ ! -f "$patch_file" ]; then echo "Missing patch file: $patch_file" return 1 fi done < "$quilt_dir/series"
# Validate patch format find "$quilt_dir" -name "*.patch" -exec git apply --check {} \; 2>/dev/null
echo "Patch preparation complete"}
prepare_quilt_patches "quilt-patches/"Integration with Development Workflows:
Section titled “Integration with Development Workflows:”Kernel Development Workflow:
Section titled “Kernel Development Workflow:”#!/bin/bash# Kernel development quilt integration
kernel_patch_workflow() { local kernel_version="$1" local quilt_series="$2"
echo "Importing kernel patches for version $kernel_version"
# Set up kernel repository git checkout "v$kernel_version" git checkout -b "kernel-$kernel_version-patched"
# Import quilt patches git quiltimport --patches "$quilt_series" \ --author "Kernel Team <kernel@project.org>"
# Verify import imported_commits=$(git rev-list HEAD --count) echo "Imported $imported_commits commits"
# Run kernel build test make defconfig && make -j$(nproc) 2>&1 | head -20
echo "Kernel patch import complete"}
kernel_patch_workflow "5.15" "/path/to/kernel-patches"Open Source Project Maintenance:
Section titled “Open Source Project Maintenance:”# Maintain patches for upstream projectsmaintain_upstream_patches() { local upstream_repo="$1" local patch_dir="$2"
echo "Maintaining patches for upstream project"
# Sync with upstream git fetch "$upstream_repo" git rebase "FETCH_HEAD"
# Apply maintained patches git quiltimport --patches "$patch_dir" \ --keep-non-patch
# Test integration run-tests.sh
# Update patch series if needed echo "Patches maintained and tested"}
maintain_upstream_patches "upstream" "my-patches/"Collaborative Patch Development:
Section titled “Collaborative Patch Development:”# Collaborative patch development workflowcollaborative_patches() { local patch_repo="$1" local contributor="$2"
echo "Importing patches from contributor $contributor"
# Clone contributor's patch repository git clone "$patch_repo" contributor-patches cd contributor-patches
# Import patches into main branch git quiltimport --author "$contributor <contributor@example.com>"
# Review imported patches git log --oneline --author="$contributor" -10
# Merge into main project cd .. git remote add contributor contributor-patches git merge contributor/main
echo "Collaborative patches integrated"}
collaborative_patches "https://github.com/user/patches.git" "Jane Doe"Troubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Missing Author Information:
Section titled “Missing Author Information:”# Handle missing author informationfix_missing_authors() { local patches_dir="$1"
echo "Checking for missing author information"
# Scan patches for author info find "$patches_dir" -name "*.patch" | while read -r patch; do if ! grep -q "^From:" "$patch" && ! grep -q "^Author:" "$patch"; then echo "Missing author in: $patch"
# Extract from git history if possible patch_name=$(basename "$patch" .patch) possible_author=$(git log --format="%an <%ae>" --grep="$patch_name" | head -1)
if [ -n "$possible_author" ]; then echo "Suggested author: $possible_author" fi fi done
echo "Use --author flag to specify default author"}
fix_missing_authors "patches/"Patch Application Failures:
Section titled “Patch Application Failures:”# Handle patch application failuresdebug_patch_failures() { local failed_patch="$1"
echo "Debugging patch application failure: $failed_patch"
# Check patch format head -20 "$failed_patch"
# Test patch application git apply --check "$failed_patch" 2>&1 || { echo "Patch has conflicts or format issues"
# Try with different options git apply --whitespace=fix "$failed_patch" 2>&1 || { echo "Patch needs manual fixing" return 1 } }
# Check for quilt-specific issues if grep -q "^Index:" "$failed_patch"; then echo "Quilt-style patch detected" fi
echo "Patch debugging complete"}
debug_patch_failures "patches/001-broken.patch"Series File Issues:
Section titled “Series File Issues:”# Fix series file problemsvalidate_series_file() { local series_file="$1" local patches_dir="$2"
echo "Validating series file: $series_file"
# Check series file exists if [ ! -f "$series_file" ]; then echo "Series file not found: $series_file" return 1 fi
# Validate each patch reference local line_num=1 while read -r line; do # Skip comments and empty lines [[ "$line" =~ ^[[:space:]]*# ]] || [ -z "$line" ] && continue
# Extract patch filename patch_file=$(echo "$line" | awk '{print $1}')
# Check patch exists if [ ! -f "$patches_dir/$patch_file" ]; then echo "Missing patch file on line $line_num: $patch_file" return 1 fi
((line_num++)) done < "$series_file"
echo "Series file validation passed"}
validate_series_file "patches/series" "patches/"Encoding and Format Issues:
Section titled “Encoding and Format Issues:”# Handle encoding and format problemsfix_encoding_issues() { local patches_dir="$1"
echo "Fixing encoding and format issues"
# Convert patches to UTF-8 find "$patches_dir" -name "*.patch" | while read -r patch; do if ! file "$patch" | grep -q "UTF-8"; then echo "Converting $patch to UTF-8" iconv -f latin1 -t utf8 "$patch" > "${patch}.utf8" mv "${patch}.utf8" "$patch" fi done
# Fix line endings find "$patches_dir" -name "*.patch" -exec dos2unix {} \;
# Normalize patch format find "$patches_dir" -name "*.patch" | while read -r patch; do # Ensure proper patch headers if ! grep -q "^---" "$patch"; then echo "Warning: $patch may not be in standard patch format" fi done
echo "Encoding fixes applied"}
fix_encoding_issues "patches/"Dependency and Ordering Issues:
Section titled “Dependency and Ordering Issues:”# Handle patch dependency problemsresolve_dependencies() { local series_file="$1"
echo "Analyzing patch dependencies"
# Create dependency graph (simplified) declare -A patch_deps
# For each patch, check what files it modifies while read -r line; do [[ "$line" =~ ^# ]] || [ -z "$line" ] && continue
patch_file=$(echo "$line" | awk '{print $1}') modified_files=$(grep "^+++ " "$patch_file" | sed 's/+++ [ab]\///')
patch_deps["$patch_file"]="$modified_files" done < "$series_file"
# Check for conflicts for patch1 in "${!patch_deps[@]}"; do for patch2 in "${!patch_deps[@]}"; do if [ "$patch1" != "$patch2" ]; then # Check for overlapping files common_files=$(comm -12 \ <(echo "${patch_deps[$patch1]}" | tr ' ' '\n' | sort) \ <(echo "${patch_deps[$patch2]}" | tr ' ' '\n' | sort))
if [ -n "$common_files" ]; then echo "Potential conflict between $patch1 and $patch2" echo "Common files: $common_files" fi fi done done
echo "Dependency analysis complete"}
resolve_dependencies "patches/series"Real-World Usage Examples:
Section titled “Real-World Usage Examples:”Kernel Patch Management:
Section titled “Kernel Patch Management:”#!/bin/bash# Kernel patch management with quiltimport
kernel_patch_management() { local kernel_version="$1" local quilt_repo="$2"
echo "Managing kernel patches for version $kernel_version"
# Set up kernel tree git clone "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git" cd linux git checkout "v$kernel_version"
# Create patch branch git checkout -b "patches-$kernel_version"
# Import quilt patches git quiltimport --patches "$quilt_repo/patches" \ --series "$quilt_repo/series" \ --author "Kernel Maintainers <maintainers@kernel.org>"
# Verify kernel builds make defconfig make -j$(nproc) modules_prepare 2>&1 | head -20
if [ "${PIPESTATUS[0]}" -eq 0 ]; then echo "✓ Kernel patches imported successfully" else echo "✗ Kernel build failed after patch import" exit 1 fi
# Create patch documentation git log --oneline --reverse > "PATCHES-$kernel_version.txt" echo "Patch list saved to PATCHES-$kernel_version.txt"}
kernel_patch_management "6.1" "/path/to/kernel-quilt"Embedded Systems Development:
Section titled “Embedded Systems Development:”# Embedded systems patch managementembedded_patch_workflow() { local board_config="$1" local patch_set="$2"
echo "Managing patches for embedded board: $board_config"
# Set up base system git checkout "base-$board_config" git checkout -b "patched-$board_config"
# Import board-specific patches git quiltimport --patches "$patch_set/board-patches" \ --author "Board Team <board@company.com>"
# Import BSP patches git quiltimport --patches "$patch_set/bsp-patches" \ --author "BSP Team <bsp@company.com>"
# Test build make BOARD="$board_config" 2>&1 | head -20
# Create release tag git tag "release-$board_config-$(date +%Y%m%d)"
echo "Embedded patches integrated for $board_config"}
embedded_patch_workflow "raspberry-pi-4" "/path/to/board-patches"Collaborative Patch Review:
Section titled “Collaborative Patch Review:”# Collaborative patch review workflowpatch_review_workflow() { local patch_repo="$1" local reviewer="$2"
echo "Reviewing patches from $patch_repo"
# Clone patch repository git clone "$patch_repo" review-patches cd review-patches
# Dry run import to check patches git quiltimport --dry-run --author "$reviewer <reviewer@company.com>"
# Import patches for review git quiltimport --author "$reviewer <reviewer@company.com>"
# Review each imported commit git log --oneline --reverse | while read -r commit_line; do commit=$(echo "$commit_line" | cut -d' ' -f1) subject=$(echo "$commit_line" | cut -d' ' -f2-)
echo "Reviewing: $subject" git show "$commit" | head -50
# Interactive review read -p "Accept this patch? (y/n/skip): " decision case "$decision" in "n") echo "Patch rejected: $subject" git reset --hard HEAD~1 ;; "skip") echo "Patch skipped: $subject" ;; *) echo "Patch accepted: $subject" ;; esac done
# Push reviewed patches git push origin main
echo "Patch review complete"}
patch_review_workflow "https://github.com/user/feature-patches.git" "Senior Developer"Automated Patch Testing:
Section titled “Automated Patch Testing:”# Automated patch testing pipelineautomated_patch_testing() { local patch_dir="$1" local test_script="$2"
echo "Running automated patch testing"
# Create test branch git checkout -b "test-patches-$(date +%Y%m%d-%H%M%S)"
# Import patches git quiltimport --patches "$patch_dir" \ --author "CI System <ci@company.com>"
# Test each patch individually git log --oneline --reverse | while read -r commit_line; do commit=$(echo "$commit_line" | cut -d' ' -f1) subject=$(echo "$commit_line" | cut -d' ' -f2-)
echo "Testing patch: $subject"
# Run test suite if $test_script; then echo "✓ Tests passed for: $subject" else echo "✗ Tests failed for: $subject" echo "Failing commit: $commit"
# Revert failing patch git reset --hard HEAD~1 break fi done
# Report results successful_patches=$(git rev-list HEAD --count) echo "Successfully applied $successful_patches patches"
if [ "$successful_patches" -gt 0 ]; then echo "Test results: PASS" else echo "Test results: FAIL" exit 1 fi}
automated_patch_testing "patches/" "./run-tests.sh"Legacy Code Migration:
Section titled “Legacy Code Migration:”# Migrate legacy patches to Gitlegacy_migration() { local legacy_patches="$1" local target_repo="$2"
echo "Migrating legacy patches to Git repository"
# Set up target repository git clone "$target_repo" migration-target cd migration-target
# Create migration branch git checkout -b "migrated-patches"
# Convert legacy patches to quilt format if needed if [ -d "$legacy_patches" ]; then # Assume patches are already in quilt format patch_dir="$legacy_patches" else # Convert from other formats echo "Converting patches from legacy format..." # Conversion logic here patch_dir="converted-patches" fi
# Import patches git quiltimport --patches "$patch_dir" \ --keep-non-patch \ --author "Migration Team <migration@company.com>"
# Validate migration imported_count=$(git rev-list HEAD --count) echo "Migrated $imported_count patches"
# Test build if [ -f "Makefile" ] || [ -f "build.sh" ]; then make clean && make 2>&1 | head -20 if [ "${PIPESTATUS[0]}" -eq 0 ]; then echo "✓ Build successful after migration" else echo "⚠ Build issues detected" fi fi
# Create migration report git log --oneline --reverse > "MIGRATION-REPORT.txt" echo "Migration report saved"
echo "Legacy migration complete"}
legacy_migration "/path/to/legacy-patches" "https://github.com/company/project.git"Patch Series Maintenance:
Section titled “Patch Series Maintenance:”# Maintain and update patch seriesmaintain_patch_series() { local series_name="$1" local upstream_repo="$2"
echo "Maintaining patch series: $series_name"
# Sync with upstream git fetch "$upstream_repo" git rebase "FETCH_HEAD"
# Update patches if needed if [ -d "patches-$series_name" ]; then echo "Updating existing patch series"
# Refresh patches git format-patch --output-directory="patches-$series_name" \ --numbered \ "origin/main..HEAD"
# Update series file ls patches-$series_name/*.patch | sed 's|.*/||' > "patches-$series_name/series"
echo "Patch series updated" else echo "Creating new patch series"
# Export current patches git quiltimport --patches "patches-$series_name" \ --author "Maintainer <maintainer@project.org>"
echo "Patch series created" fi
# Archive patch series tar czf "${series_name}-$(date +%Y%m%d).tar.gz" "patches-$series_name/" echo "Patch series archived"}
maintain_patch_series "security-fixes" "upstream"What’s the difference between quiltimport and git am?
Section titled “What’s the difference between quiltimport and git am?”quiltimport imports entire patch series preserving boundaries, while git am applies individual patches. quiltimport maintains patch order and descriptions from quilt series.
How do I prepare patches for quiltimport?
Section titled “How do I prepare patches for quiltimport?”Ensure patches are in quilt format with proper headers, create a series file listing patches in order, and verify all patches can be applied cleanly.
Can quiltimport handle patch dependencies?
Section titled “Can quiltimport handle patch dependencies?”Yes, it applies patches in the order specified in the series file, maintaining dependencies between patches.
What if patches have conflicts during import?
Section titled “What if patches have conflicts during import?”quiltimport will stop at the first conflict. Resolve conflicts manually, then continue with git am —continue or restart the import process.
How do I specify author information for patches?
Section titled “How do I specify author information for patches?”Use —author “Name
Can quiltimport work with compressed patches?
Section titled “Can quiltimport work with compressed patches?”No, patches must be uncompressed text files. Use gunzip or similar to decompress patches before import.
What’s the —keep-non-patch option for?
Section titled “What’s the —keep-non-patch option for?”—keep-non-patch preserves files in the patches directory that aren’t .patch files, useful for maintaining additional patch-related files.
How do I validate patches before importing?
Section titled “How do I validate patches before importing?”Use —dry-run to check for missing information and potential issues without applying patches.
Can quiltimport import patches from git format-patch?
Section titled “Can quiltimport import patches from git format-patch?”Yes, git format-patch creates patches compatible with quiltimport. Use —numbered option for proper ordering.
What’s the difference between series file and patch files?
Section titled “What’s the difference between series file and patch files?”Series file lists patches in application order; patch files contain the actual diff content with metadata.
How do I handle patches with different encodings?
Section titled “How do I handle patches with different encodings?”Convert patches to UTF-8 before import. Use iconv or similar tools to handle encoding issues.
Can quiltimport work with binary patches?
Section titled “Can quiltimport work with binary patches?”No, quiltimport only works with text-based patches. Binary changes should be handled differently.
How do I resume an interrupted quiltimport?
Section titled “How do I resume an interrupted quiltimport?”Check git status, resolve any conflicts, then use git am —continue if using git am, or restart quiltimport from the failed patch.
What’s the impact of quiltimport on repository history?
Section titled “What’s the impact of quiltimport on repository history?”quiltimport creates one Git commit per quilt patch, preserving the patch’s author, date, and description.
Can quiltimport handle quilt’s .pc directory?
Section titled “Can quiltimport handle quilt’s .pc directory?”No, quiltimport doesn’t use quilt’s internal state. It only reads the series file and patch files.
How do I convert existing quilt patches to Git?
Section titled “How do I convert existing quilt patches to Git?”Use quiltimport directly on the patches directory, or use git am on individual patches if you don’t need to preserve quilt structure.
Can quiltimport work with remote patch repositories?
Section titled “Can quiltimport work with remote patch repositories?”Yes, clone or download the patch repository first, then run quiltimport on the local patch directory.
Applications of the git quiltimport command
Section titled “Applications of the git quiltimport command”- Legacy Code Migration: Converting quilt-managed patches to Git commits
- Kernel Development: Importing kernel patches while preserving patch boundaries
- Collaborative Development: Managing patch series from multiple contributors
- Embedded Systems: Maintaining board-specific and BSP patches
- Open Source Maintenance: Managing patches for upstream project maintenance