...
- Find the repo for the patch file.
- Clone the repo. For ex:
- Checkout Checkout the branch for which you want to create the patch.
- $ git checkout 1905_sprint
Branch '1905_sprint' set up to track remote branch '1905_sprint' from 'origin'.
Switched to a new branch '1905_sprint' - $ git branch
* 1905_sprint
master
4. Find the location of the patch file in the repo.
- $ find . -iname index.patch
./meta-pacexf3/recipes-ccsp/ccsp/ccsp-webui/index.patch
Step 2 :
- Next find the repo for the actual source file to which the patch file was getting patched.
- clone the repo.
- checkout the required branch.
- $ git checkout 1905_sprint
Branch '1905_sprint' set up to track remote branch '1905_sprint' from 'origin'.
Switched to a new branch '1905_sprint' - $ git branch
* 1905_sprint
master
...
- Cherry-pick the required changes also.
...
5. After cherry-picking you can verify the changes in the source file.
Step 3 :
- create another directory, and clone the source code repo (as in step 2). For ex :
- $ mkdir dummy
- $ cd dummy/
- $ git clone ssh://rkumar840@gerrit.teamccp.com:29418/rdk/rdkb/components/opensource/ccsp/webui/generic
$ git checkout 1905_sprint
Branch '1905_sprint' set up to track remote branch '1905_sprint' from 'origin'.
Switched to a new branch '1905_sprint'
- $ git branch
* 1905_sprint
master
Copy the patch file from the patch repo (step 1) to the current directory.
- $ cp ../patch/meta-pacexf3/recipes-ccsp/ccsp/ccsp-webui/index.patch .
- $ ls
cmpnt_build_custom_pre_arm.mkCONTRIBUTING.md debug_scripts LICENSE NOTICE scripts
cmpnt_build_custom_pre_pc.mk COPYING index.patch Makefile.orig README source
Apply the patch to the source file.
- $ patch -p1 < index.patch
patching file source/Styles/xb3/code/index.php
Hunk #1 succeeded at 22 (offset 21 lines).
Hunk #2 succeeded at 32 (offset 21 lines).
Hunk #3 succeeded at 73 (offset 21 lines).
Hunk #4 succeeded at 183 (offset 27 lines).
Hunk #5 succeeded at 195 (offset 27 lines).
Hunk #6 succeeded at 245 (offset 37 lines).
Hunk #7 succeeded at 307 (offset 37 lines).
Hunk #8 succeeded at 445 (offset 37 lines).
Hunk #9 succeeded at 454 (offset 37 lines).
Hunk #10 succeeded at 468 (offset 37 lines).
Hunk #11 succeeded at 482 (offset 37 lines).
Hunk #12 succeeded at 492 (offset 37 lines).
It should be applied successfully.
Take a backup for the file got patched.
For ex :
$ cp source/Styles/xb3/code/index.php source/Styles/xb3/code/index_bk.php
Step 4 :
- Now you can use "Meld tool" to compare between files to refresh the patch. Here you can compare between the source file generated in step 2 (which will have the required changes) and the source file generated in step-3 (which will have the patch appied on to it).
- During comparing between source files make sure that you take only the required changes (changes available in actual source file step-2) to the patched file generated in step-3.
- Once all changes are taken , you can verify the patch by checking the option file/format as patch in the tool. Save the updated file and copy it to your repo (repo generated in step-2).
- Now in your repo , you will have 2 source file (for ex: one will be index.php --original file with the required changes and index_bk.php --updated file with patch applied and also your changes).
- In terminal , you can use command "diff -ruN file1 file2 > new_patch_file.patch" to generate a new patch.
- For ex : diff -ruN index.php index_bk.php > new_index.patch
Step 5 :
- Open the newly created patch file, update the file location correctly and save it. For ex :
--- git/source/Styles/xb3/code/index.php 2019-05-20 05:56:54.047078876 +0000
+++ git.1/source/Styles/xb3/code/index.php 2019-05-20 06:26:56.000000000 +0000
Step 6 :
- In order to verify the newly created patch, you can create a temporary folder, clone the repo, checkout the required branch. Now copy the latest patch (new_index.patch) here.
- In the terminal, give the command patch -p1 < new_index.patch, will apply the patch to the source file. It should not fail.
step 7 :
- Now for pushing the latest patch, clone the repo for patch (step-1)
- $ mkdir push
- $cd push/
- $ git clone ssh://rkumar840@gerrit.teamccp.com:29418/rdk/yocto_oe/layers/meta-rdk-oem-pace-broadcom .
- checkout the required branch.
- $ git checkout 1905_sprint
- copy the latest patch(new_index.patch in this case) to the actual patch file available in the repo.
- $ cp ../src/new_index.patch meta-pacexf3/recipes-ccsp/ccsp/ccsp-webui/index.patch
- $ git status
- It will show the file as modified. Perform git add.
- $ git add meta-pacexf3/recipes-ccsp/ccsp/ccsp-webui/index.patch
- $ git commit
- Update if any commit message has to be added and try to push the changes.
- $ git push origin HEAD:refs/for/1905_sprint
- It fails for commit message upload. For ex : you may get error like this :
- remote: ERROR: [6b429fb] missing Change-Id in commit message footer
- remote:
- remote: Hint: To automatically insert Change-Id, install the hook:
- remote: gitdir=$(git rev-parse --git-dir); scp -p -P 29418 rkumar840@gerrit.teamccp.com:hooks/commit-msg ${gitdir}/hooks/
- remote: And then amend the commit:
- remote: git commit --amend
- Run the command mention in logs.
- $ gitdir=$(git rev-parse --git-dir); scp -p -P 29418 rkumar840@gerrit.teamccp.com:hooks/commit-msg ${gitdir}/hooks/
- $ git commit --amend (No change-id is assigned to the change.)
- $ git commit --amend (change-id has assigned now.)
- $ git push origin HEAD:refs/for/1905_sprint
- This will push the changes successfully to the branch. You can open the gerrit link and verify.
- Put the same topic name for the patch and the source file , trigger the verification.
...