Skip to content

Instantly share code, notes, and snippets.

@zxhfighter
Last active October 24, 2019 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zxhfighter/f28d3d2f84cb6a6ebfcbffdaff7edf77 to your computer and use it in GitHub Desktop.
Save zxhfighter/f28d3d2f84cb6a6ebfcbffdaff7edf77 to your computer and use it in GitHub Desktop.
how to user git format-patch and git am

如何生成 patch 和应用 patch

生成 patch

git format-patch

git format-patch HEAD^         # 生成最近的1次commit的patch
git format-patch HEAD^^        # 生成最近的2次commit的patch
git format-patch <r1>..<r2>    # 生成版本 r1-r2 之间的patch
git format-patch <r1>          # 生成版本 r1 以来的patch(不包含r1)
git format-patch -1 commit-id  # 选定的那个commit打patch

应用 patch

git am

git apply --stat 0001-limit-log-function.patch    # 查看patch的情况
git apply --check 0001-limit-log-function.patch   # 检查patch是否能够打上,如果没有输出,则无冲突,可以打上
git am 0001-limit-log-function.patch # 将名字为0001-limit-log-function.patch的patch打上
git am --abort # 废弃 patch
git am --resolved # 解决完冲突,接着去打 patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment