Tips on
Patch:How to merge a patch into a project
WAY ONE
1. $
repo start
.
It aims to avoid taking impact on other branches (at least on the
original remote branch).
The command "$ repo
start ." is designed
to pull out a new topical branch from
the revision specified in the manifest.xml
file. "$git
branch " and "$git checkout ", the two commands
are equal to the one command "$ git checkout -b ". They are
designed to pull a branch from the Head of the current
branch.
All
subsequent opertaions are done in the newly created topical branch
unless user switches among topical branches
and remote branches.
2. $git am [--reject]
Split mail messages in a mailbox into commit log message,
authorship info and patches, and applies them to the current local
branch. This "--reject" option makes it apply the parts of the
patch that are applicable, and leave the rejected hunks(parts) in
corresponding *.rej
files.
2.1 If a patch is applied succefully, the below similar tips will
be printed out.
********************************************************
*Applying:
*Checking patch ...
*Applied patch cleanly.
*..............................
*Checking patch ...
*Applied patch cleanly.
********************************************************
2.2 If a patch fails to be applied, the below similar tips will be
printed out.
********************************************************
*Applying:
*Checking patch ...
*error: while searching for:
* ..........................
*error: patch failed: :
*Applying patch with * reject...
*Rejected hunk #
*Patch faild at
********************************************************
When
it fails to apply a patch by command "$git am", user
can run
1)"git am --skip"
command to skip the current patch, or
run
2)"git am --abort"
command to restore the original branch and stop patching this
time.
At
above two cases, user need delete reject files ($git clean -f ),
if the "$git am" command was executed with option
"--reject".
3) also manually resolve conflicts in the working tree according to
*.rej files and make a commit with "$git am --resolved"
command.
3.1) Use "$git status" or "$gitk" command to
check the working tree status.
3.2) Add by hand the rejected changes into
the target file according to *.rej
files.
3.3) Delete
un-necessary files by "$rm " or "$git clean -f" command, including
backup and rejected files from working tree.
3.4) Update available files into index area from working tree by
"$git add " or "$git add ." command.
3.5) Attempting to re-apply patch's changes into HEAD commit from
index area after resolving conflict by "$git am --resolved"
command.
3. $git commit --amend
Only
modify or check the commit message.
4. $repo upload .
upload the
commit into Gerrit Code Review System to review.
Notes:
1) When using "$git am" command to apply a patch,
once a hunk in this patch does not match with its
relative target file or some other issues
ocurs, this command will abort in the middle, but
it's still in the process of git-am command. User
cannot apply another patch by git-am command and print below tips
untill user run "git am --skip" to skip the current patch or run
"git am --abort" to restore the original branch
and stop the current patching.
***************************************************************************************
previous rebase directory
/home/CORPUSERS/xp012906/sourcecode/jb-mr2-blue-test/frameworks/av/.git/rebase-apply
still exists but mbox
given.
*************************************************************************************22)
When "$git am"
command fails to apply a patch, this command will save some
information in related files in ".git/rebase-apply/" folder in the
project path.
-
The
file "001" is a full copy of patch file.
-
The file "patch" only is the diff section copy of patch
file.
-
The file "msg" only is the message body copy of patch
file.
-
The file "info" store the author name, author mail,
commit message subject and date the commit message
submitted.
WAY
TWO
1. $repo start .
2. $git
apply --reject
Read the patch and
applies changes to related
files.
git-apply
only applies a patch but does not create a
commit. It neend use
"$git-commit" to create a commit.
For atomicity, git-apply by default fails the whole patch and does
not touch the working tree when any hunk does not apply. The
"--reject" option makes it apply the parts of the patch that are
applicable, and leave the rejected hunks in corresponding *.rej
files.
3. resolve conflicts
4. $git status, gitk, git add
5. $git
commit
6. $repo
upload .
WAY
THREE
1. $repo start .
2. $patch -p1
<<BR>
Try to apply this patch into the current branch.
Format: patch [options] <
patch
command is similar to git-apply command. It only
applies a patch but does not create a commit. It
neend use "$git-commit" to create a
commit.
3. resolve conflicts
4. $git status, gitk, git add
5. $git commit
6. $repo upload .
Notes:
1) "$git apply" and "$git am" commands can be executed only in
project path.
If
it need cherry pick a commit from a branch to another, and project
path has changed, user only can modify the relative path of every
hunk in patch file.
2) "$patch" command can be executed in the scope of a project. So
when project path has changed, user can choose proper relative path
to run "$patch" command.
For example, when user does gap-close from jb-mr2-rhine branch to
jb-mr2-blue branch.
Suppose that the project path of a commit in jb-mr2-rhine branch is
"vendor/qcom/proprietary/mm-parser",
and its project path in jb-mr2-blue branch is
"vendor/qcom/proprietary/".
It's very convenient for user to run "$patch -p1 < " in
"vendor/qcom/proprietary/mm-parser" path of jb-mr2-blue branch to
apply patch.
However, as far as "git apply" or "git am" command is
concerned,
Firstly user need modify the relative path of every hunk in patch
file.
******************************************************************************
* diff --git a/Android_adaptation/src/MMParserExtractor.cpp
b/Android_adaptation/src/MMParserExtractor.cpp
* index 8167e4f..4af8b5d 100644
* --- a/Android_adaptation/src/MMParserExtractor.cpp
* +++ b/Android_adaptation/src/MMParserExtractor.cpp
******************************************************************************
||
||
||
\/
******************************************************************************
* diff --git
a/mm-parser/Android_adaptation/src/MMParserExtractor.cpp
b/Android_adaptation/src/MMParserExtractor.cpp
* index 8167e4f..4af8b5d 100644
* ---
a/mm-parser/Android_adaptation/src/MMParserExtractor.cpp
* +++
b/mm-parser/Android_adaptation/src/MMParserExtractor.cpp
******************************************************************************
And then in the "vendor/qcom/proprietary/" project path of
jb-mr2-blue branch to run "$git apply" or "git am" command.
3)Since "patch" or "git cherry-pick" command will try their best
efforts to resolve conflicts, or since "patch" or
"git cherry-pick" command recognizes a hunk respectively according
to the above background and the below background context,
but "git apply" or "git am" command recognizes a
hunk according to the whole context, it is more
convenient to run "patch" or "git cherry-pick" command to apply a
patch than "git apply" or "git am" command.
WAY FOUR
1. $ repo start .
2.
$git am
3. $git apply
--reject
Read the
patch and applies it to files.
This command applies a patch but does not create a commit. Need use
"$git-am" to create commits from patches generated by
git-format-patch.
4.
According to *.rej files, add by hand the rejected changes into
the target file, or use "kddif3 " tool to compare
the source file and the
corresponding target file, find the difference between the two
files, and finally add manually the rejected changs into the
corresponding target
file.
5. $git status, $git add, $gitk
6. $git am --resolved
Attempting
to re-apply patch's changes into index after resolving
conflict.
7. $git commit --amend
Only modify
or check the commit message.
8. $repo upload .
upload the
commit into Gerrit Code Review System to review.
加载中,请稍候......