[clug] Telling git to not update files across braches

jm jeffm at ghostgun.com
Tue Aug 7 05:34:29 UTC 2018


Thanks for the walk through. I'm sure this will be useful to others that
stumble upon it. It looks as if the only bit I was missing was the "git
config ..."  As you said there are other way to handle environment
specific files. This isn't for a web app but for managing files for  a
~3GB filesystem image. Thinking about this over the weekend I may simply
create a directory structure environment/$branch and place those files
in there then rely on the build script to copy those files over the top
of the base files. This may work better when the repo has to be shared
with others as it uses the standard git work flow (don't have to
remember to do "git merge -s ours master"  instead of "git merge master").

Jeff.

On 1/08/2018 21:23, Chris Smart via linux wrote:
> There may be other ways to handle your environment configs, but anyway, I think your .gitattributes file also needs a filename/regex to match on.
>
> Basically what you're doing there is specifying a merge strategy called "ours" for any files that match. You also need to define the "ours" strategy in your git config (locally or globally) and then when you merge in a branch you can specify that strategy (it will use "ours" if there's a conflict in the files, but there may not always be).
>
> Here's an example of something which should work:
>
> $ git init
> Initialized empty Git repository in /tmp/git/.git/
>
> (master#)$ git config merge.ours.driver true # uses bash builtin for true
>
> (master #)$ echo "config.yaml merge=ours" > .gitattributes
>
> (master #%)$ git add .gitattributes
>
> (master +)$ git commit -m "add gitattributes to ignore config on merge"
> [master (root-commit) 9d63728cae51a809] add gitattributes to ignore config on merge
>  1 file changed, 1 insertion(+)
>  create mode 100644 .gitattributes
>
> (master)$ cat > config.yaml << EOF
> environment:
>   - name: dev
>     server: dev-hostname
> EOF
>
> (master %)$ git add config.yaml
>
> (master +)$ git commit -m "add config for dev"
> [master 6dd23a88f24aa4cb] add config for dev
>  1 file changed, 3 insertions(+)
>  create mode 100644 config.yaml
>
> (master)$ git checkout -b prod
> Switched to a new branch 'prod'
>
> (prod)$ cat > config.yaml << EOF
> environment:
>   - name: prod
>     server: prod-hostname
> EOF
>
> (prod *)$ cat config.yaml 
> environment:
>   - name: prod
>     server: prod-hostname
>
> (prod *)$ git add config.yaml
>
> (prod +)$ git commit -m "add config for prod"
> [prod ca30a00ee306939d] add config for prod
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> (prod)$ cat config.yaml 
> environment:
>   - name: prod
>     server: prod-hostname
>
> (prod)$ git checkout master
> Switched to branch 'master'
>
> (master)$ cat config.yaml 
> environment:
>   - name: dev
>     server: dev-hostname
>
> (master)$ git merge -s ours prod
> Merge made by the 'ours' strategy.
>
> (master)$ cat config.yaml 
> environment:
>   - name: dev
>     server: dev-hostname
>
> (master)$ git checkout prod
> Switched to branch 'prod'
>
> (prod)$ git merge -s ours master
> Merge made by the 'ours' strategy.
>
> (prod)$ cat config.yaml 
> environment:
>   - name: prod
>     server: prod-hostname
>
> -c
>




More information about the linux mailing list