我正在寻找从最后一次提交创建补丁的命令。

我的工作流程有时是这样的:

vi some.txt
git add some.txt
git commit -m "some change"

现在我只想写:

git create-patch-from-last-commit-to-file SOME-PATCH0001.patch

我应该在那里写什么,而不是从最后提交到文件创建补丁?


当前回答

你需要-p选项git log:

git log -1 -p --pretty='%b'

其他回答

你需要-p选项git log:

git log -1 -p --pretty='%b'
git format-patch -1

这是我的工作。

一般来说,

git format-patch -n HEAD^

(查看帮助中的许多选项),尽管它实际上是为了邮寄它们。 对于单个提交

git show HEAD > some-patch0001.patch

会给你一个有用的补丁。

另一种方法,如果有特定commit的commit id, 你可以用,

git format-patch -1 {commit-id}

从@Useless answer中,你也可以使用最后一次提交不带参数的一般形式,并将其放入一个文件中:

git format-patch HEAD^ --stdout > patchfile.patch

或者,当必须通过加倍转义插入符号时,对windows用户来说更干净:

git format-patch HEAD~1 --stdout > patchfile.patch