Git
binary files
conflict resolution
version control
software development

Resolving a Git conflict with binary files

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Understanding Git Conflicts with Binary Files

Git is a powerful version control system known for its distributed nature and efficiency with text-based files. However, dealing with binary files in Git can be challenging, especially when conflicts arise. This article explores the intricacies of resolving Git conflicts with binary files, providing you with the knowledge and techniques needed to manage such scenarios effectively.

What Are Binary Files?

Binary files are non-text files that store data in a format that is not human-readable. Common examples include images, compiled programs, and audio files. Unlike text files, which can be easily merged line by line using diff tools, binary files require special handling due to their opaque nature.

How Git Handles Binary Files

Git is superbly optimized for managing text files by efficiently storing differences. Unfortunately, it treats binary files as opaque blobs. It does not attempt to perform a git diff or merge automatically. This limitation can lead to conflicts when multiple contributors make changes to the same binary file, simultaneously creating different versions.

Resolving Conflicts with Binary Files

When a binary file conflict occurs in Git, you must choose between conflicting versions manually. This process might involve using external tools or backup systems to select the most appropriate version. Below are several strategies to resolve such conflicts:

1. Overwriting Changes

  • Choose Source: You can resolve the conflict by choosing either your version or the version from the other branch completely.
    • Using Your Version:
    • Using Their Version:
  • Commit Changes:
  • Adobe Photoshop: For images in formats like PSD.
  • Beyond Compare or WinMerge: Both support plugins for some binary file types.
  • Find the Commit ID:
  • Checkout the Previous Version:
  • Commit the Reverted Version:
  • Avoid Binary Files: Where possible, avoid adding frequently changed binary files to your repository. Use text-based alternatives where feasible.
  • Git LFS: Use Git Large File Storage (LFS) for handling large binary files efficiently. It stores binary files outside your repository, with pointers that Git can track.
  • Metadata Modification: Limits changes to metadata rather than the file’s content to reduce conflicts.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.