• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

“git format-patch” Command Examples

by admin

“git format-patch” is a Git command used to prepare patch files for sharing and submitting changes to others, especially when communicating via email or other means. It generates a series of patch files, typically in the “.patch” format, that contain the changes introduced by one or more commits.

Here’s how “git format-patch” works:

  • Commit Selection: When using “git format-patch,” you can specify the commits you want to include in the patch files. This can be done by specifying commit ranges, individual commits, or even using Git’s revision selection mechanisms. For example, you can specify a range of commits like git format-patch origin/master..HEAD to generate patches for all commits between the current branch’s HEAD and the “origin/master” branch.
  • Patch Generation: Once you’ve selected the commits, “git format-patch” generates a separate patch file for each commit. Each patch file represents a single commit and contains the changes made in that commit in a textual format. The patch file includes information such as the commit message, author, and the changes made to the files.
  • Patch File Naming: By default, “git format-patch” names the patch files using a numbering scheme, such as “0001-CommitMessage.patch”, “0002-CommitMessage.patch”, and so on, based on the order of the selected commits. The numbering helps in maintaining the order of the patches when applying them.
  • Patch Application: The generated patch files can be applied to another Git repository using the “git am” command. The recipient can use “git am” to apply the patches and incorporate the changes into their own repository. This allows for easy sharing and applying of changes between different Git repositories.

Using “git format-patch,” you can prepare a series of patch files that encapsulate the changes made in specific commits. These patch files can then be sent via email or shared in other ways to exchange code changes, review code, or collaborate with others who may not have direct access to your Git repository.

By providing a convenient way to generate patch files, “git format-patch” simplifies the process of sharing changes, especially when communicating through email or when using external collaboration tools. It allows for easy code review, discussion, and integration of changes across different repositories and development workflows.

git format-patch Command Examples

1. Create an auto-named .patch file for all the unpushed commits:

# git format-patch origin

2. Write a .patch file for all the commits between 2 revisions to stdout:

# git format-patch revision_1..revision_2

3. Write a .patch file for the 3 latest commits:

# git format-patch -3

Filed Under: Linux

Some more articles you might also be interested in …

  1. git info: Display Git repository information
  2. ping Command Examples in Linux
  3. asterisk Command Example
  4. lastb: command not found
  5. How to uninstall local-apt-repository software package in Ubuntu
  6. pvremove Command Examples in Linux
  7. CentOS / RHEL : How to Install and Configure OpenSSH Server and Client
  8. duc Command Examples in Linux
  9. userdel Command Examples in Linux
  10. grex Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright