Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make change to a git submodule, and keep the changes

I've cloned a git submodule of one of my libraries into a project I'm working on. The thing is that, after cloning, I need to change some lines in the cloned submodule, but I don't want to push those changes into the original repository.

I want those changes to stay in the superproject. Is this possible? How can I achieve that?

EDIT: As @GoZoner said, basically its:

  1. git clone foo;
  2. cd foo;
  3. git submodule init;
  4. git submodule update;
  5. cd path/to/submodule;
  6. git checkout master;
  7. Make changes to the submodule
  8. git commit -am "Something";
  9. git push origin (the superproject);

Then when I clone the superproject in another computer (up to step 4), I want those changes to be saved, in the superproject.

like image 406
AeroCross Avatar asked Jun 01 '12 19:06

AeroCross


People also ask

Can I make changes to a submodule?

Pushing updates in the submodule. The submodule is just a separate repository. If you want to make changes to it, you should make the changes in its repository and push them like in a regular Git repository (just execute the git commands in the submodule's directory).

How do I change a submodule in a repository?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

How do I sync submodule?

git submodule sync synchronizes all submodules while git submodule sync -- A synchronizes submodule "A" only. If --recursive is specified, this command will recurse into the registered submodules, and sync any nested submodules within.


1 Answers

I think you need to relax the 'no commit to submodule' constraint. There are two options:

  1. Commit your submodule changes to a submodule branch. It is your team's branch and it is where your team put your submodule changes. When somebody clones the super project and updates the submodule they get the content of your team's branch.
  2. Clone the submodule repository 'right next to' your super project repository and initialize the submodule to point to your clone. Then when you commit changes to the submodule they are committed to your clone. Anybody who clones the super project gets submodule content from your submodule clone.

Otherwise, I don't see a way to achieve your desire.

like image 50
GoZoner Avatar answered Sep 29 '22 05:09

GoZoner