Detailed use git am

copy from : http://blog.chinaunix.net/uid-27714502-id-3435780.html

 

Article mainly introduce the use git-am and the format-patch. Because git use them, there will be many when others (suppliers or other developers) sent me a series of patch , the patch is usually like this name:

0001--JFFS2-community-fix-with-not-use-OOB.patch 0002--Community-patch-for-Fix-mount-error-in.patch 0003--partial-low-interrupt-latency-mode-for-ARM113.patch 0004--for-the-global-I-cache-invalidation-ARM11.patch 0005--1-arm-Add-more-cache-memory-types-macr.patch 0006--2-Port-imx-3.3.0-release-to-2.6.28.patch 0007--3-Add-MX25-support.patch 0008--Move-asm-arch-headers-to-linux-inc-dir.patch 0009--1-regulator-allow-search-by-regulator.patch

Which contains the information in the log, author, date submitted. You want to do is put these patch introduced into your code base, preferably also the log can also be introduced in, to facilitate future maintenance use. The traditional way is to play patch

patch -p1 < 0001--JFFS2-community-fix-with-not-use-OOB.patch

So to play patch, but so will the useful information is lost. Since these patch apparently with git format-patch to generate, so use git tools should be able to do well. git-am is for this thing.

Before using git-am, you must first git am -abort time to give up the previous am information, so that it can conduct a new am.
Or you will encounter this error.
                .git / rebase-apply still exists but mbox given.

git-am can merge a file at a time, or a directory patch in all patch, or your mail directory.

The following two examples:

  1. You now have a code base: small-src, your patch files in ~ / patch / 0001-trival-patch.patch

     

cd small-src git-am ~/patch/0001-trival-patch.patch

If successful patch up, you can go to a cup of tea. If it fails, git will prompt an error, such as:

error: patch failed: android/mediascanner.cpp:452 error: android/mediascanner.cpp: patch does not apply

So you need to look at the patch, then change to change the file errors, so the patch can patch up.

  1. You have a bunch of patch, patch a bunch of name is that mentioned above, you put them under ~ / patch-set / directory (path freely)

     

cd opencore git am ~/patch-set/*.patch

(Here git will be in the order of the file name once am these patch) If all goes well, all of you patch are OK, you have a Lucky. But do not go well, when in all likelihood, if git am middle encountered a patch, am will stop place to fight this patch, and tell you which patch not get to play.

For example, I now have a document file, there are two Patch.
File content is

the text more text

Two patch are:

0001-add-line.patch:

From 8869ccbced494e05738090afa5a54f2a261df0f Mon Sep 1700:00:00 2001 From: abc abc@abc-desktop.(none) Date: Thu, 22 Apr 2010 13:04:34 +0800 Subject: [PATCH 1/2] add line --- file | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/file b/file index 067780e..685f0fa 100644 --- a/file +++ b/file @@ -3,3 +3,5 @@ file: some text more text + +add line -- 1.6.3.3

0002-change-line.patch:

From f756e1b3a87c216b7e0afea9d15badd033171578 Mon Sep 17 00:00:00 2001 From: abc abc@abc-desktop.(none) Date: Thu, 22 Apr 2010 13:05:19 +0800 Subject: [PATCH 2/2] change line --- file | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/file b/file index 685f0fa..7af7852 100644 --- a/file file: -some text +Change line text more text -- 1.6.3.3

Run
git am * .patch

To merge the patch, error, Patch failed at 0001 add line we look at 0001 this patch, the original patch is needed is some text, and file inside the text, so we use this editor to change the line some text,

vi file git apply 0001-add-line.patch git add file git am --resolved

After completion of resolving conflicts, such as using git add git to let know you have done to resolve the conflict.

    • If you find that this conflict can not be solved, to withdraw am whole thing. You can run git am -abort,
    • If you want to just ignore this patch, you can run git am -skip to skip this patch.

Guess you like

Origin www.cnblogs.com/Oude/p/12521943.html