我如何简单地从我最新的 git 提交中创建一个补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9396240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I simply create a patch from my latest git commit?
提问by claj
I'm looking for the magic command of creating a patch from the last commit made.
我正在寻找从最后一次提交创建补丁的神奇命令。
My workflow sometimes looks like this
我的工作流程有时看起来像这样
vi some.txt
git add some.txt
git commit -m "some change"
and now I just want to write
现在我只想写
git create-patch-from-last-commit-to-file SOME-PATCH0001.patch
but what should i put there instead of create-patch-from-last-commit-to-file
?
但我应该把什么放在那里而不是create-patch-from-last-commit-to-file
?
回答by Useless
In general,
一般来说,
git format-patch -n HEAD^
(check help for the many options), although it's really for mailing them. For a single commit just
(检查许多选项的帮助),尽管它实际上是为了邮寄它们。对于单个提交
git show HEAD > some-patch0001.patch
will give you a useable patch.
会给你一个可用的补丁。
回答by a1an
Taking from @Useless answer, you can also use the general form with no parameters for the last commit and put it into a file with:
从@Useless 答案中获取,您还可以使用不带参数的一般形式用于最后一次提交,并将其放入文件中:
git format-patch HEAD^ --stdout > patchfile.patch
Or, being cleaner for windows users when carets have to be escaped by doubling them:
或者,当必须通过加倍来逃避插入符号时,对于 Windows 用户来说更干净:
git format-patch HEAD~1 --stdout > patchfile.patch
回答by Vijay C
another way, if have the commit id of that particular commit, you can use,
另一种方式,如果有那个特定提交的提交 ID,你可以使用,
git format-patch -1 {commit-id}
回答by Brandan
You need the -p
option to git log:
您需要-p
git log 选项:
git log -1 -p --pretty='%b'
回答by Katu
git format-patch -1
Does the job for me.
为我做这份工作。