How can I update kernel source to newer one without losing added code?

2.9k views Asked by At

I have a snapshot of the android kernel source code from a while ago, to which I have added some features. Now I have a newer version of the source published by manufacturer. How can I update my source without losing my changes? If i use

diff -Naur old/ new/ > new1.patch

"" then apply patch by

patch -p1 < new1.patch

I will lose modified code and extra files that were available in old source but if I use

diff -Naur new/ old/ > new2.patch

It preserves my modified code and extra files, but I don't know if the source is updated or not. Is there any solution for this? Perhaps using git rebase or merge? Thanks.

1

There are 1 answers

4
Gauthier On BEST ANSWER

Do I understand correctly: you had a kernel version provided by your manufacturer, to which you made your own modifications?

Then you want to upgrade your kernel version, but still have your modification?

The most natural way is to work with branches and merges. For example, you could update your branch master according to the deliveries from your manufacturer, and maintain a branch my_code_branch (of course, you need a much better branch name than this) to which you merge upstream kernel updates.

a---b---c---d - master (from manufacturer)
             \
              +---x - my_branch (your own changes)

Then when an upgrade comes from your manufacturer, you update your master with:

$ git checkout master
$ git pull origin master # or whatever your remote is called

and get:

a---b---c---d---e - master (from manufacturer)
             \
              +---x - my_branch (your own changes)

Then merge the changes from your manufacturer, into your own branch:

$ git checkout my_branch
$ git merge master

to get:

a---b---c---d---e---+ - master
             \       \
              +---x---y - my_branch

If you don't need the local master branch, you could also stay on my_branch and pull directly:

$ git pull origin master   # while on my_branch

Note that you could also do the opposite: your code in master while maintaining a branch manufacturer that you'd keep up-to-date with the manufacturer.