1

I'm trying to set up a script to automatically rebase changes from the development branch to branches containing Maven child modules.

The way this project is setup is that the development branch contains the parent module. All changes go to that module and so are merged to the development branch. In order for the child modules to get these chagnes, the must be rebased onto development. The child modules themselves should never be modified in a rebase.

When I try to use my script to rebase the child branch onto development, I get a conflict stating that the child module has been deleted on the development branch. This makes sense, as that module does not exist in development. I need the rebase to ignore anything to do with the child module, so I added this line to .gitignore in the project:

*_module/

The naming convention of each child module has '_module' at the end, so with *, then each branch should be able to ignore the child module in question, regardless of name. However, this has not worked. I've yet to find anything regarding this use case, and am wondering if anyone else has any advise on how to proceed.

Here is the general file structure of the development branch:

project+
       |
       +-src+ #parent module
       |    |
       |    +-main #where changes to the code occure
       |
       +.gitattributes
       |
       +.gitignore
       |
       +pom.xml

And here is the structure of a branch with a child module:

project+
       |
       +-test1_module+ #child module in maven.  Need to ignore this in .gitignore, or some equivalent
       |             |
       |             +-src+ 
       |                  |
       |                  +-assembly
       |                  |
       |                  +-main
       |
       +-src+ #parent module
       |    |
       |    +-assembly
       |    |
       |    +-main 
       |
       +.gitattributes
       |
       +.gitignore
       |
       +pom.xml

EDIT: To be clear, I do not want to delete this child module from the git repository; I simply want to ignore or skip over any changes to it during a rebase.

SVill
  • 331
  • 5
  • 22
  • 55

1 Answers1

0

.gitignore can only ignore untracked content.

So each branch should need to:

git rm -r --cached test*_module
echo "*_module/">>.gitignore

And add and commit.
Then the rebase would not yield any conflict.

But: that is not what the OP is after, which means .gitignore is not the solution anyway.

In this instance, the rebase script should need to, on conflict (for the child module),

  • accept changes from "theirs" (through, git checkout -- theirs -- test1Module).
  • add, and resume rebase (git add .; git rebase --continue) This assume than the maven module can be fetched automatically through a maven dependency, which means it does not have to be versioned in the parent repository.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm don't think this is what I'm looking for. When I run this command, it deletes the child module from the repository. I can't lose that child module; I simply need to ignore any changes to it during a rebase. – SVill Nov 05 '19 at 13:41
  • @SVill I understand: I simply illustrated that `.gitignore` only works for *untracked* content, hence the `git rm`. – VonC Nov 05 '19 at 13:57
  • @SVill I have edited the answer to propose an alternative approach. – VonC Nov 05 '19 at 14:12