Git apply a patch to the working directory

26,281

Solution 1

You can use git apply which applies a patch:

git apply < patchname.patch

This does not create any commits. In fact, without any options the git apply command doesn't even need to have a Git repository. It just applies patches to files.

Solution 2

You can use a patch command, e.g.:

patch -p1 < path/file.patch

When using patch command, it will usually auto-detect the format. This is useful when you're trying to apply patch to the working directory which isn't a local checkout of the project you wish to patch.

Otherwise use git apply if your patch was created specifically for the project, otherwise it will fail to do anything when used within a local checkout of a git repository.

Solution 3

Try this command line

git am < patchname.patch
Share:
26,281

Related videos on Youtube

Omar
Author by

Omar

omar.io github.com/omar

Updated on August 28, 2022

Comments

  • Omar
    Omar 4 months

    I have a patch that contains a lot of changes that I would like to split into multiple commits and potentially modify some of the changes.

    I want to apply this patch to my working directory and then manually commit the changes. Is it possible to apply a patch to the working directory in git?

  • Omar
    Omar about 11 years
    That does a normal patch apply, adding it to the repository (i.e. a regular commit).

Related