Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply changes on a different base path using git

Tags:

git

The project I'm working with was build using ant in the past. A few weeks ago it was modularized and migrated to maven. Thus the project structure changed and the src directory paths. From e.g. /src to /module-A/src/main/java.

So the repository looks like this

       mavenization        master
           V                 |
                             V
o----o-----o-----o-----o-----o      <-- maven project with module-A/src/main/java
    \
     \
      o-----o-----A                 <-- still an ant project with `/src`
                  ^
                  |
           maintenance branch

The maintenance branch is the one that was released weeks ago and is now the bugfix branch for production.

My problem is that I have to fix a bug in the mainenance branch and of course apply it to the master.But this doesn't work, because the project structure changed with the mavenization commit.

Well, the directory structure under the /module-A/src/main/java is the same as on the maintenance branch's /src directory. But since the base directory differs I guess a cherry-pick is not possible or do you know some option?

Of course I could merge the files manually or using a tool like WinMerge, but I'm looking for a better solution using git.

How can I apply the changes of commit A with a different base path to the master branch?

like image 220
René Link Avatar asked Aug 16 '26 04:08

René Link


1 Answers

Make a patch of the mavenization commit. Suppose the commit hash is abc123.

git format-patch -1 abc123

And you will get a patch named 0001.xxx.patch.

Switch to master:

git checkout master

Apply the patch:

git am 0001.xxx.patch --directory=module-A/

git apply also works this way.

like image 103
ElpieKay Avatar answered Aug 19 '26 15:08

ElpieKay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!