Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git `format-patch` returns nothing

Tags:

git

I am trying to create a patch for a commit in my repository.

  • System: Windows 10
  • Tools Git Windows Desktop and Git Shell git --version => git version 2.10.1.windows.1

When I try to create the patch I go:

git format-patch master
git format-patch master -o C:\Users\MyUser\Desktop
git format-patch master --stdout > C:\Users\MyUser\Desktop\MyPatch.patch

In all 3 cases, I get nothing. In the first 2 cases, no file is saved in the locations I specify. In the third case, the generated file is 0 bytes.

State of my repository

I have pushed everything to master. So I have no more local unstaged or staged commits. Everything is on the server.

Also, if I change a file and have unstaged changes, still it does not work.

I've also tried:

git format-patch <ccommit-sha>

Using the SHA hash of a commit I pushed. Still does not work.

What am I doing wrong?

like image 460
Andry Avatar asked Feb 06 '23 19:02

Andry


1 Answers

To create patch you need to specify what should be used to create it. If you want to create patch using last commit from main branch just call git format-patch -1 main.

In case you will need to create patch (patches) for some specific commit, a SHA-1 value can be used in place of the branch name.

For more information, please check format-patch documentation.

It might be worth of mentioning that if you will use SHA-1 hash of a commit that is after your current commit (later timestamp),

This is caused by the way patches are created. Git documentation for git-format-patch says the patch is technically output of the execution of

diff -p stat

which creates a diff between a commit and its parent. The parent is a key in this case. If you want to create a patch between your current repository state (for example checked out comit) and one that is in the future, it's not possible, because that future commit is not a parent, but a child.

like image 67
Kamil Avatar answered Feb 08 '23 08:02

Kamil