Git subtree workflow
Asked Answered
B

4

3

In my current project I'm using an open source forum ( https://github.com/vanillaforums/Garden ). I was planning on doing something like this :

git remote add vanilla_remote https://github.com/vanillaforums/Garden.git
git checkout -b vanilla vanilla_remote/master
git checkout master
git read-tree --prefix=vanilla -u vanilla

This way I can make change into the vanilla folder (like changing config) and commit it to my master branch and I can also switch into my vanilla branch to fetch updates. My problem is when I try to merge the branch together

git checkout vanilla
git pull
git checkout master
git merge --squash -s subtree --no-commit vanilla
git commit -a -m "update commit"

The problem is that the "update commit" goes on top of my commits and "overwrite" my change. I would rather like to have my commits replay on top of the update. Is there a simple way to do that? I'm not very good in git so maybe this is the wrong approach. Also, I really don't want to mix my history with the vanilla history.

Burley answered 25/6, 2011 at 0:43 Comment(3)
I have the same problem, I just want to do this (from git-scm.com/book/en/Git-Tools-Subtree-Merging): "All the changes from your Rack project are merged in and ready to be committed locally. You can also do the opposite — make changes in the rack subdirectory of your master branch and then merge them into your rack_branch branch later to submit them to the maintainers or push them upstream." And THEN do the merge command. They mention it but there is no sample command.Locarno
@ernipiggy Did you find a way to push from a subtree?Shortfall
@Shortfall I tried to explain it belowLocarno
L
3

I finished up with this scheme:

  1. Work on my development branch touching files from the subtree.

  2. Update the subtree branch with squashed development commits:

    git merge -s subtree --squash --no-commit development

  3. Update the subtree branch with its remote repository.

  4. Update development with squashed subtree commits:

    git merge --squash -s subtree --no-commit subtree

Locarno answered 15/1, 2013 at 2:42 Comment(0)
S
3

If you're looking to work with subtrees, you probably want to use git subtree. It provides a somewhat more user-friendly interface to this sort of thing, including merge/pull commands to merge in a subtree (squashing is optional) and split/push commands to split back apart changes to a subtree and send them back to its own repo.

Synergy answered 25/6, 2011 at 18:51 Comment(0)
L
3

I finished up with this scheme:

  1. Work on my development branch touching files from the subtree.

  2. Update the subtree branch with squashed development commits:

    git merge -s subtree --squash --no-commit development

  3. Update the subtree branch with its remote repository.

  4. Update development with squashed subtree commits:

    git merge --squash -s subtree --no-commit subtree

Locarno answered 15/1, 2013 at 2:42 Comment(0)
E
1

Using

git merge --squash -s subtree --no-commit vanilla

will not "overwrite" your change. I am hoping by "update commit" you mean the commit you did after the subtree merge since it has --no-commit and will not commit by itself.

Elongation answered 25/6, 2011 at 4:45 Comment(1)
Yes exactly. Still, from that point the only way I can get the correct behavior is to rebase -i and to push back that commit under my changes and I don't really like that..Burley
C
0

I too am not a git master (see what I did there ;-) ) ... however, I think you may want to look at the rebase command:

http://book.git-scm.com/4_rebasing.html

Caputo answered 25/6, 2011 at 0:48 Comment(1)
Thanks but I don't see how the rebase command could be of any help because the two branch don't share any common "base".Burley

© 2022 - 2024 — McMap. All rights reserved.