git patch 使用

从某个commit生产patch

1
git format-patch --stdout -1 <SHA> > what_do.patch

应用patch,并stage

1
git apply --index what_do.patch

patch包含多个commit , git am 应用并自动提交,一般大家都喜欢git am!!

1
git am -3 < your_patch_file.patch

the -3 will do a three-way merge if there are conflicts. At this point you can do a git mergetool if you want to go to a gui or just manually merge the files using vim (the standard <<<<<<, ||||||, >>>>>> conflict resolution).

冲突解决后执行 git am –resolve

不想解决冲突,git am –abort