What is the difference between 'git format-patch and 'git diff'?

前端 未结 3 1336
[愿得一人]
[愿得一人] 2020-12-04 11:00

I don\'t see a difference between the output of \'git format-patch\' and \'git diff\', is there any? And won\'t I be able to use \'git diff\' to produce a patch and then app

3条回答
  •  死守一世寂寞
    2020-12-04 11:36

    From the manuals git-format-patch prepares patches suitable for email submission, while git-diff shows changes.

    They are two different things and have different purposes, they just happen to output a patch format. But git-format-patch adds data about a commit (date, author, commit message) and bundles it up into a format that is suitable for sending as a Unix mail message (although these are just files, so they can be sent to other methods and still applied by git-am).

    Also git-format-patch generates a patch file for each commit in the range that you specify. These changes will be added as commits to your repository with git-am.

    git-diff just shows the diff between the two states you ask for, and can be used to create a patch file. But this is just a normal patch file and applying the patch will just change the state of the working directory.

    And yes, you can create a patch for your index that way.

提交回复
热议问题