1、生成某次commit之后的patch
miyuehu@s6:~/repo/m$ git format-patch c92ec02610efac65d2bf979127541400416d1610
0001-add-build.sh.patch
0002-v1.4-released.patch
2、生成某次commit的patch
miyuehu@s6:~/repo/m$ git format-patch -1 c92ec02610efac65d2bf979127541400416d1610
0001-v1.4.patch
3、am patch出错后的处理
miyuehu@s6:~/repo/tmp$ git am < 0001-fix-bug-with.patch
Applying: fix bug with
/home/miyuehu/repo/tmp/.git/rebase-apply/patch:220: trailing whitespace.
/home/miyuehu/repo/tmp/.git/rebase-apply/patch:245: trailing whitespace.
error: patch failed: android/device/*.java:307
error: android/device/*.java: patch does not apply
error: patch failed: android/device/**.java:27
error: android/device/**.java: patch does not apply
error: patch failed: android/device/***.java:30
error: android/device/***.java: patch does not apply
Patch failed at 0001 fix bug with
The copy of the patch that failed is found in:
/home/miyuehu/repo/tmp/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
此时,无需执行git am --continue/git am --skip/git am --abort
执行
miyuehu@s6:~/repo/tmp$ git apply --reject 0001-fix-bug-with.patch
0001-fix-bug-with.patch:21: trailing whitespace.
Log.i(TAG, "post onFailure");
0001-fix-bug-with.patch:28: trailing whitespace.
Log.i(TAG, "post onFinish");
0001-fix-bug-with.patch:35: trailing whitespace.
Log.i(TAG, "post onStart");
0001-fix-bug-with.patch:42: trailing whitespace.
Log.i(TAG, "post onSuccess");
0001-fix-bug-with.patch:55: trailing whitespace.
FileInfo mFileInfo;
Checking patch android/device/*.java...
Checking patch android/device/**.java...
Checking patch android/device/***.java...
Applied patch android/device/*.java cleanly.
Applied patch android/device/**.java cleanly.
Applied patch android/device/***.java cleanly.
warning: squelched 24 whitespace errors
warning: 29 lines add whitespace errors.
执行
miyuehu@s6:~/repo/tmp$ git status
On branch v1.4
Your branch is up-to-date with 'origin/v1.4'.
You are in the middle of an am session.
(fix conflicts and then run "git am --continue")
(use "git am --skip" to skip this patch)
(use "git am --abort" to restore the original branch)
Changes not staged for commit:
(use "git add
(use "git checkout --
modified: android/device/*.java
modified: android/device/**.java
modified: android/device/***.java
modified: "doc/100\345\215\207\347\272\247\346\226\207\346\241\243.doc"
PS:這里应该显示中文的,需要配置git
miyuehu@s6:~$ git config --global core.quotepath false
miyuehu@s6:~$ vim .gitconfig
[user]
name = miyuehu
email = [email protected]
[core]
quotepath = false
這里git就能显示中文了。
miyuehu@s6:~/repo/tmp$ git status -uno
On branch v1.4
Your branch is ahead of 'origin/v1.4' by 7 commits.
(use "git push" to publish your local commits)
You are in the middle of an am session.
(fix conflicts and then run "git am --continue")
(use "git am --skip" to skip this patch)
(use "git am --abort" to restore the original branch)
Changes not staged for commit:
(use "git add
(use "git checkout --
modified: android/device/*.java
modified: android/device/**.java
modified: android/device/***.java
modified: doc/100升级文档.doc
执行
miyuehu@s6:~/repo/tmp$ git add android/device/*
fix conflicts and then run "git am --continue"
miyuehu@s6:~/repo/tmp$ git am --continue