13

The short of what's below: I want to push commit messages to a subtree, but only the messages that apply to that tree. How do I do this?


I have two projects, Master and Slave. Slave is checked out as a subtree of Master checked out to lib/slave via git subtree merge --prefix=lib/slave --squash projects/slave where projects/slave is a branch that Slave is checked out into:

Branches:

master projects/slave → slave

Now I'm working on my master branch, making commits to files that are part of both projects, everything is going smoothly. Now I want to push changes back to Slave:

  • git checkout slave
  • git merge ??? master

If I do a normal merge I get commits for every commit to master, whether or not any files in lib/slave were modified. Or I can do a --squash and only get a single commit, but I lose the log messages.

So how do I get the appropriate log messages? e.g. if my master log history is:

  • added images to master
  • modified files in slave only
  • more changes to master only
  • modified files in master and slave

I'd want this added to Slave:

  • modified files in slave only
  • modified files in master and slave
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Gitslave (http://gitslave.sourceforge.net/) might have been an interesting alternative in your case. – VonC Apr 10 '12 at 13:35
  • @VonC -- One of the main problems I see with gitslave is that it seems to fork commands to each repo, effectively doing `git commit -m"commit message"` on each repo. So if any developers aren't using it, we're going to be running into sync issues, correct? –  Apr 12 '12 at 20:14
  • Possibly the stupidest question in the world, but why isn't `git log ` sufficient here? That'll give you only the changes pertinent to your slave branch when you issue it across your directories. Is your pain in the change clutter, or is it just in the display? – MrGomez Apr 15 '12 at 08:31
  • @MrGomez -- because I want to actually push those changes to different repositories –  Apr 15 '12 at 19:12

1 Answers1

7

For the behavior you want, I think you'll have to push from Master, I don't know of a way to pull subtree changes from Slave.

To push changes:

(in Master)
$ git subtree split --prefix=lib/slave -b split-branch
$ git push <bare Slave repo> split-branch:master
$ git branch -d split-branch
$ cd /path/to/Slave/working/copy
$ git pull  # (now in Slave)

The first command creates a new subtree based on the directory, which is then pushed to the other project.

In theory, you should be able to push directly to a working copy, but in practice that didn't work for me.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
  • I wasn't sure why you don't show a `git subtree push` command, but then I realized (from the git subtree docs) that a subtree push is just a subtree split followed by a regular push to the alternate repository. – yoyo Apr 06 '17 at 21:54