Roots Discourse

Best practices to update Trellis

git merge should give you conflicts that you’d need to resolve manually. Maybe --squash or --no-commit is suppressing that but not sure off the top of my head.

I haven’t done a merge like that before. I have cherry picked commits to keep my project synced up, that seems to work pretty well, and like Scott mentioned, if there are any issues you will have to resolve a merge conflict, which will allow you to preserve your project’s updates.

@kalenjohnson That’s the thing, there aren’t any merge conflicts because the merge overwrites everything automatically. I’m left with a vanilla Trellis.

I’ll keep sniffing round :slight_smile:

I’ve never seen that happen automatically… usually you’d have to explicit set a strategy using -X theirs (meaning “for conflicts use theirs as the winner”).

Hi - @swalkinshaw is correct in that you should (and I do) get notification that merge conflicts should be updated:

Automatic merge failed; fix conflicts and then commit the result.

It does look like the update method needs investigation - I’ve just run through the process on a test repo on trellis/bedrock/sage branches and the branches seem to be over writing each other. Ie. update the ‘bedrock’ branch and the sage files are deleted. I’ll look into it more thoroughly.

EDIT - I found that I had to use a more specific command for the git merge step:

git merge -X subtree=trellis/ --squash trellis/master

and then manually resolve any resulting conflicts.

obviously likewise:

git merge -X subtree=site/ --squash bedrock/master

7 Likes

@chrisk2020 I’m running into the composer fail error above and I think that I definitely need to update trellis because the fix was pushed in only two days ago. However, I’m really not that smart and I don’t understand the git commands that I need to use. Any chance you could explain it to me? I think I need to add a new remote, cherry pick the commit I want, merge into my repo?..I’m confused…:frowning:

what exactly is the message you are getting?

I was following your blog post and when I ran “git read-tree --prefix=trellis/ -u trellis/master” I got “error: Entry ‘trellis/.editorconfig’ overlaps with ‘trellis/.editorconfig’. Cannot bind.”

1 Like

I ran into the same error today. I was on an existing project where the subtrees had not been setup from the get go and various commits had already taken place.

if you skip the read-tree command and instead do git merge -X subtree=trellis/ --squash trellis/master it should work ok - there should be merge conflicts that represent your local changes. resolve these and you should be good. I’ve not had much chance to test, but it seemed to work fine for me.

1 Like

Thanks. I have another stupid question…How do I resolve the conflicts? This is the first time I’ve done anything other than commit changes to git. I type git status and see the files but how do I tell it what to leave and what to change?

Macintosh-2:nationalsafetystanddown.com Tom$ git merge -X subtree=trellis/ --squash trellis/master
Removing trellis/vars/sudoer_passwords.yml
Auto-merging trellis/roles/wordpress-setup/templates/wordpress-site.conf.j2
CONFLICT (content): Merge conflict in trellis/roles/wordpress-setup/templates/wordpress-site.conf.j2
Auto-merging trellis/roles/php/tasks/main.yml
CONFLICT (content): Merge conflict in trellis/roles/php/tasks/main.yml
CONFLICT (modify/delete): trellis/roles/composer/tasks/main.yml deleted in trellis/master and modified in HEAD. Version HEAD of trellis/roles/composer/tasks/main.yml left in tree.
Auto-merging trellis/requirements.yml
CONFLICT (content): Merge conflict in trellis/requirements.yml
Auto-merging trellis/hosts/staging
CONFLICT (content): Merge conflict in trellis/hosts/staging
Auto-merging trellis/hosts/production
CONFLICT (content): Merge conflict in trellis/hosts/production
Auto-merging trellis/group_vars/staging/wordpress_sites.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/staging/wordpress_sites.yml
Auto-merging trellis/group_vars/staging/vault.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/staging/vault.yml
Auto-merging trellis/group_vars/production/wordpress_sites.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/production/wordpress_sites.yml
Auto-merging trellis/group_vars/production/vault.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/production/vault.yml
Auto-merging trellis/group_vars/development/wordpress_sites.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/development/wordpress_sites.yml
Auto-merging trellis/group_vars/development/vault.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/development/vault.yml
Auto-merging trellis/group_vars/all/users.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/all/users.yml
Auto-merging trellis/group_vars/all/main.yml
CONFLICT (add/add): Merge conflict in trellis/group_vars/all/main.yml
Auto-merging trellis/deploy-hooks/build-before.yml
CONFLICT (add/add): Merge conflict in trellis/deploy-hooks/build-before.yml
Auto-merging trellis/Vagrantfile
CONFLICT (content): Merge conflict in trellis/Vagrantfile
Auto-merging trellis/README.md
CONFLICT (content): Merge conflict in trellis/README.md
Auto-merging trellis/CHANGELOG.md
CONFLICT (content): Merge conflict in trellis/CHANGELOG.md
Squash commit – not updating HEAD
Automatic merge failed; fix conflicts and then commit the result.
Macintosh-2:nationalsafetystanddown.com Tom$ git status
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
(use “git reset HEAD …” to unstage)

modified:   trellis/.editorconfig
modified:   trellis/.gitignore
modified:   trellis/.travis.yml
new file:   trellis/filter_plugins/trellis_filters.py
deleted:    trellis/vars/sudoer_passwords.yml

Unmerged paths:
(use “git reset HEAD …” to unstage)
(use “git add/rm …” as appropriate to mark resolution)

both modified:   trellis/CHANGELOG.md
both modified:   trellis/README.md
both modified:   trellis/Vagrantfile
both added:      trellis/deploy-hooks/build-before.yml
both added:      trellis/group_vars/all/main.yml
both added:      trellis/group_vars/all/users.yml
both added:      trellis/group_vars/development/vault.yml
both added:      trellis/group_vars/development/wordpress_sites.yml
both added:      trellis/group_vars/production/vault.yml
both added:      trellis/group_vars/production/wordpress_sites.yml
both added:      trellis/group_vars/staging/vault.yml
both added:      trellis/group_vars/staging/wordpress_sites.yml
both modified:   trellis/hosts/production
both modified:   trellis/hosts/staging
both modified:   trellis/requirements.yml
deleted by them: trellis/roles/composer/tasks/main.yml
both modified:   trellis/roles/php/tasks/main.yml
both modified:   trellis/roles/wordpress-setup/templates/wordpress-site.conf.j2

@tinytoolbox I know this is not a specific answer to your question, but you may want to get started with an OS X app for doing this kind work. I learned so much with Tower and Kaleidoscope, but SourceTree is a good free start at it (and multi-platform too).

4 Likes

Yeah - how to use git - is a little bit out of my scope here. The list of files look like I’d suspect. You’ll see inside each conflicted file something like

<<<<<<< head
something from your repo here
==========
<<<<<<<<trellis/master
something new - or from the other branch here
==========

you replace the one you don’t want to keep with the one you do - therefore resolving the conflict. Then add and commit. and that should be that.

Hope that helps a bit.

1 Like

Thanks again Chris. I really appreciate it. I googled how to resolve git conflicts and nothing explained it that simply. I really am just faking this whole “developer” thing. Luckily I’m just working for myself. Cheers!

Thanks. I ended up getting a trial version of Tower and using the comparison tool to resolve my conflicts. MY BEDROCK/TRELLIS SETUP IS WORKING!!! Yay!!!

1 Like

@tinytoolbox That’s great news.

Currently, I keep ‘trellis’ & ‘site’ (bedrock + theme) in different git repositories as it was easier for me to merge changes with Tower when the two are separated. My two next big steps are figuring out how to use Cherry Picking and, more importantly, getting each project into one repository and using git Subtrees with the git merge commands from @chrisk2020.

Edit: I now have everything in one repository…much nicer. The GUIs of Tower and SourceTree cannot be easily be used for the subtree git merge. Use the CLI instead.

1 Like

In my case I had to remove the trailing slash after subtree=trellis, otherwise it gave the error: fatal: entry not found in tree

Apart from that, so far the method seems to work fine. Thanks for the article @chrisk2020

you definitely want a good diff app and Kaleidoscope is quite good. easy on the eyes. kdiff3 is your free alternative. any other means of resolving a messy merge is insanity.

1 Like

I haven’t tried this approach yet so I haven’t yet had to deal with merge conflicts, etc. But with this subtree approach is it possible to rebase instead of merge? The idea would be to rebase the entire Trellis/Bedrock/Sage repos with their updates and then apply all your app specific changes on top of those changes. It might help minimize conflicts? Does that conceptually make sense?

1 Like

FYI - if anyone is using this method and getting this error message:

fatal: refusing to merge unrelated histories

it’s because the default changed in git 2.9; see this SO question.

Add --allow-unrelated-histories to make the command work again:

git merge -X subtree=trellis/ --squash trellis/master --allow-unrelated-histories 

:slight_smile:

9 Likes