gitgit-commitgit-patch

How to create git patch from two files?


I am a newbie to git and I was just wondering, if it's possible to create a git patch from two different file. There is no git repo, the scenario is that I have a file and I modified it, now I want to create a patch with the difference between these two files. Any pointers? Or should I just go ahead with creating a repo and then modifying the file and then commit the changes?


Solution

  • Looking at the git diff man page, you can try with:

    git diff --no-index --patch 
    

    With:

    git diff --no-index [--options] [--] [<path>…]
    

    This form is to compare the given two paths on the filesystem.
    You can omit the --no-index option when running the command in a working tree controlled by Git and at least one of the paths points outside the working tree, or when running the command outside a working tree controlled by Git.

    Since:

    You should be able to use git diff outside a git repo without any issue.

    Example:

    git diff --no-index --patch --output=mypatch.diff file1 file2