تخطَّ إلى المحتوى

Delta Cheatsheet

Delta Cheatsheet

ورقة إرشادات Delta السريعة

Installation

التثبيت

Basic Commands

الأوامر الأساسية

Advanced Usage

الاستخدامات المتقدمة

Configuration

الإعدادات

Delta is configured through Git’s configuration system. Configuration can be set globally ( يتم إعداد Delta من خلال نظام إعدادات Git. يمكن تعيين الإعدادات بشكل عام (

) or per-repository ( ) أو لكل مستودع (

Basic Configuration

الإعدادات الأساسية

Complete Configuration Example

مثال كامل للإعدادات

Custom Feature Sets

مجموعات الميزات المخصصة

Create reusable configuration profiles: إنشاء ملفات تعريف إعدادات قابلة لإعادة الاستخدام:

مواضيع بناء الجملة الشائعة

Common Use Cases

حالات الاستخدام الشائعة

Use Case 1: Daily Code Review Workflow

حالة الاستخدام 1: سير عمل مراجعة التعليمات البرمجية اليومية

Use Case 2: Comparing Branches for Merge

حالة الاستخدام 2: مقارنة الفروع للدمج

Use Case 3: Investigating Code History

حالة الاستخدام 3: التحقيق في تاريخ التعليمات البرمجية

Use Case 4: Merge Conflict Resolution

حالة الاستخدام 4: حل تعارضات الدمج

Use Case 5: Creating Readable Diff Reports

حالة الاستخدام 5: إنشاء تقارير اختلاف مقروءة

Best Practices

أفضل الممارسات

  • Set delta globally: Configure
  • تعيين delta بشكل عام: قم بإعداد

once to use delta for all repositories, ensuring consistent diff viewing experience. مرة واحدة لاستخدام delta لجميع المستودعات، مما يضمن تجربة عرض اختلاف متسقة.

  • Enable navigation mode: Use
  • تمكين وضع التنقل: استخدم

to quickly jump between files in large diffs using للانتقال بسرعة بين الملفات في الاختلافات الكبيرة باستخدام

(next) and (التالي) و

(previous) keys. (السابق).

  • Choose appropriate themes: Select syntax themes that match your terminal background (dark/light) and provide good contrast. Test with
  • اختيار المواضيع المناسبة: حدد مواضيع بناء الجملة التي تتوافق مع خلفية طرفيتك (داكن/فاتح) وتوفر تباينًا جيدًا. اختبر مع | منصة | أمر | |----------|---------| | Ubuntu/Debian | wget https://github.com/dandavison/delta/releases/download/0.16.5/git-delta_0.16.5_amd64.deb && sudo dpkg -i git-delta_0.16.5_amd64.deb | | Arch Linux | sudo pacman -S git-delta | | Fedora/RHEL | sudo dnf install git-delta | | Alpine Linux | apk add git-delta | | macOS (Homebrew) | brew install git-delta | | macOS (MacPorts) | sudo port install git-delta | | Windows (Scoop) | scoop install delta | | Windows (Chocolatey) | choco install delta | | Windows (Winget) | winget install dandavison.delta | | Any (Cargo) | cargo install git-delta | | Verify Installation | delta --version |

Basic Commands

أمروصف
git config --global core.pager deltaاضبط delta كصفحة عرض Git الافتراضية
git diffعرض التغييرات غير المرحلة باستخدام delta
git diff --cachedعرض التغييرات المرحلة باستخدام delta
git diff path/to/file.pyعرض التغييرات في ملف محدد
git diff mainقارن الفرع الحالي مع main
git diff branch1..branch2قارن بين فرعين
git show HEADعرض آخر commit مع diff
git show abc123عرض التعديل الخاص بـ commit محدد
git log -pعرض سجل التعديلات مع الاختلافات
git diff commit1 commit2قارن بين التزامين محددين
`diff file1.txt file2.txt \delta`
delta file1.txt file2.txtقارن الملفات مباشرة باستخدام delta
delta --show-syntax-themesعرض جميع مواضيع التركيب المتاحة
delta --list-languagesقائمة بجميع لغات البرمجة المدعومة
delta --show-configعرض التكوين الحالي للدلتا
git blame file.pyعرض git blame بتنسيق delta
`git grep “function” \delta`
git diff --statعرض إحصائيات الاختلافات باستخدام delta
`git diff -w \delta`
delta changes.diffعرض ملف الفروق المحفوظ باستخدام delta

Advanced Usage

أمروصف
`git diff \delta —side-by-side`
`git diff \delta —side-by-side —width 200`
`git diff \delta —line-numbers`
`git diff \delta —syntax-theme Monokai`
`git diff \delta —language python`
git config --global delta.side-by-side trueتمكين الوضع الجانبي-بجانب عالمياً
git config --global delta.line-numbers trueتمكين أرقام السطور بشكل عام
git config --global delta.navigate trueقم بتمكين وضع التنقل للقفز بين الملفات
git config --global delta.hyperlinks trueتمكين الارتباطات التشعبية القابلة للنقر للمسار الملف
git config --global diff.colorMoved defaultقم بتمييز كتل التعليمات البرمجية المنقولة
git config --global pager.blame deltaاستخدم delta لمخرجات git blame
git config --global pager.grep deltaاستخدم delta لمخرجات git grep
git config --global interactive.diffFilter "delta --color-only"استخدم delta في أوامر Git التفاعلية
git blame -L 10,20 file.pyعرض اللوم لنطاق سطور محدد باستخدام delta
git diff --word-diffاعرض الاختلافات على مستوى الكلمات باستخدام دلتا
git config --global delta.pager "less -RFX"تخصيص سلوك الصفحة المتصفحة
git config --global delta.features "line-numbers decorations"تمكين عدة ميزات في وقت واحد
`git diff —ignore-space-at-eol \delta`
git config --global delta.max-line-length 512حدد الحد الأقصى لطول السطر للعرض
git config --global delta.tabs 4اضبط عرض علامة التبويب للعرض

Configuration

Delta is configured through Git’s configuration system. Configuration can be set globally (~/.gitconfig) or per-repository (.git/config).

Basic Configuration

[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true
    line-numbers = true
    side-by-side = true

Complete Configuration Example

[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    # General settings
    navigate = true
    light = false
    side-by-side = true
    line-numbers = true
    hyperlinks = true
    
    # Syntax highlighting
    syntax-theme = Monokai Extended
    
    # Layout
    width = 200
    tabs = 4
    wrap-max-lines = unlimited
    
    # Line numbers
    line-numbers-left-format = "{nm:>4}│"
    line-numbers-right-format = "{np:>4}│"
    line-numbers-minus-style = "red"
    line-numbers-plus-style = "green"
    line-numbers-zero-style = "white dim"
    
    # Colors and styles
    minus-style = syntax "#3f0001"
    minus-non-emph-style = syntax "#3f0001"
    minus-emph-style = syntax "#901011"
    minus-empty-line-marker-style = normal "#3f0001"
    
    plus-style = syntax "#002800"
    plus-non-emph-style = syntax "#002800"
    plus-emph-style = syntax "#007800"
    plus-empty-line-marker-style = normal "#002800"
    
    # Commit and file decoration
    commit-decoration-style = bold yellow box ul
    file-decoration-style = blue ul
    file-style = bold yellow ul
    hunk-header-decoration-style = blue box
    hunk-header-style = file line-number syntax
    
    # Whitespace
    whitespace-error-style = reverse red
    
    # Moved code detection
    color-moved-style = syntax

[diff]
    colorMoved = default

Custom Feature Sets

Create reusable configuration profiles:

[delta "my-dark-theme"]
    syntax-theme = Dracula
    line-numbers = true
    side-by-side = true
    navigate = true
    minus-style = syntax "#450a15"
    plus-style = syntax "#0a4514"

[delta "my-light-theme"]
    syntax-theme = GitHub
    light = true
    line-numbers = true
    side-by-side = false

[delta]
    features = my-dark-theme
  • Monokai Extended
  • Nord
  • Dracula
  • gruvbox-dark
  • gruvbox-light
  • Solarized (dark)
  • Solarized (light)
  • GitHub
  • OneHalfDark
  • OneHalfLight

Common Use Cases

Use Case 1: Daily Code Review Workflow

# Configure delta for optimal code review
git config --global core.pager delta
git config --global delta.side-by-side true
git config --global delta.line-numbers true
git config --global delta.navigate true

# Review changes before committing
git diff

# Review staged changes
git diff --cached

# Review specific file changes
git diff path/to/modified/file.js

Use Case 2: Comparing Branches for Merge

# Compare feature branch with main
git diff main..feature-branch

# View side-by-side comparison with context
git diff main..feature-branch | delta --side-by-side --width 180

# Check for moved code blocks
git diff --color-moved main..feature-branch

# Review specific file differences between branches
git diff main..feature-branch -- src/app.py

Use Case 3: Investigating Code History

# View commit history with diffs
git log -p --follow path/to/file.py

# Compare specific commits
git diff abc123..def456

# Show changes in a specific commit
git show abc123

# View blame with delta formatting
git blame -L 50,100 src/main.rs

# Search for changes in history
git log -p -S "function_name" | delta

Use Case 4: Merge Conflict Resolution

# Enable side-by-side view for conflicts
git config --global delta.side-by-side true
git config --global delta.line-numbers true

# View conflicted files
git diff --name-only --diff-filter=U

# Examine conflicts in detail
git diff path/to/conflicted/file.py

# Compare with both parents during merge
git diff HEAD
git diff MERGE_HEAD

Use Case 5: Creating Readable Diff Reports

# Generate formatted diff for documentation
git diff main..feature > changes.diff
delta changes.diff > formatted-changes.txt

# Create side-by-side comparison
git diff --stat main..feature
git diff main..feature | delta --side-by-side --width 200

# Export with specific theme for presentations
git diff | delta --syntax-theme "Monokai Extended" --line-numbers

Best Practices

  • Set delta globally: Configure git config --global core.pager delta once to use delta for all repositories, ensuring consistent diff viewing experience.

  • Enable navigation mode: Use git config --global delta.navigate true to quickly jump between files in large diffs using n (next) and N (previous) keys.

  • Choose appropriate themes: Select syntax themes that match your terminal background (dark/light) and provide good contrast. Test with delta --show-syntax-themesللاطلاع على جميع الخيارات. side-by-side = trueلمراجعات التعليمات البرمجية والمقارنات عند الدمج، ولكن قم بتعطيله للفحوصات السريعة على الشاشات الضيقة لتجنب مشاكل التفاف السطور. line-numbers = trueللتصحيح ومراجعات التعليمات البرمجية، ولكن فكر في تعطيله للاختلافات البسيطة لتقليل التشويش البصري. diff.colorMoved = defaultلتمييز التعليمات البرمجية التي تم نقلها بدلاً من تغييرها، مما يجعل مراجعات إعادة هيكلة التعليمات البرمجية أكثر وضوحًا. featuresوالتبديل بينها حسب الحاجة باستخدام خيار widthوtabsوwrap-max-linesبناءً على حجم الشاشة المعتاد ومعايير البرمجة لمنع كسر السطور بشكل غير مريح. interactive.diffFilter = delta --color-onlyللحصول على التمييز الخاص بـ delta فيgit add -pوالأوامر التفاعلية الأخرى لـ Git. git config --global alias.review 'diff --color-moved'لسير عمل المراجعة الموحد.

استكشاف الأخطاء وإصلاحها

مشكلةحل
Delta not being used for diffsVerify configuration with git config --global core.pager - should return delta. If not, run git config --global core.pager delta
Colors not displaying correctlyCheck terminal supports 24-bit color. Set COLORTERM=truecolor environment variable. Try different syntax themes with delta --show-syntax-themes
Side-by-side view is garbledTerminal width may be too narrow. Disable with git config --global delta.side-by-side false or increase terminal width. Adjust with --width option
Line numbers not showingEnable explicitly: git config --global delta.line-numbers true. Check that feature isn’t disabled in a custom feature set
Syntax highlighting not workingVerify file extension is recognized with delta --list-languages. Force language with --language option or check syntax-theme setting
Delta not working in git add -pSet interactive diff filter: git config --global interactive.diffFilter "delta --color-only". The --color-only flag is essential for interactive mode
Pager quits immediatelyAdjust pager settings: git config --global delta.pager "less -RFX". The -F flag causes less to quit if output fits on one screen
Performance issues with large diffsDisable side-by-side mode, reduce max-line-length, or use --syntax-theme none to disable syntax highlighting for faster rendering
Hyperlinks not clickableEnsure terminal supports hyperlinks (iTerm2, kitty, Alacritty). Enable with git config --global delta.hyperlinks true
Configuration not taking effectCheck for conflicting configs: `git config —list
Unicode characters displaying incorrectlyEnsure terminal uses UTF-8 encoding. Set LC_ALL=en_US.UTF-8 or similar locale. Check font supports Unicode characters used in decorations