0

What I would like to do is as follows;

Branch A;
|
|
\ main.c
    \ void foo() {...}
    \ void bar() {}
Branch B;
|
|
\ bar.c
    \ void bar() {...}

That is to say, with A as the main branch, and B as the child branch, I would like to merge the contents of bar.c from B into main.c from A. The only shared content between bar.c and main.c is the definition void bar() (and this is, in fact, the only contents of bar.c); the contents of this function are written in B to be merged into A. Alterations to void bar() should only occur in bar.c, within branch B to be patched in, as necessary.

I have seen similar functionality in 'diff' files (see here, for instance) and appreciate something of an answer is available here but this seems to pertain to files which are identical, unless I have misunderstood, where I intend the file in branch B to only contain a part of the primary file, main.c.

Thank you.

7
  • 1
    What's the reason you don't want to do this manually?
    – TTT
    Commented Jul 7 at 23:36
  • Hi @TTT, this is because I am intending to write to these files across a number of devices, so I thought using something like git to maintain version control would be a good idea. In addition, the example above is a minimal one; in reality, there would be a number of such child branches, each with varying complexity therein, which I feel would be difficult to maintain across a number of devices.
    – twelfth
    Commented Jul 7 at 23:40
  • I should add, I had also considered using this method for writing prose (say a technical document or article). In that scenario, each branch (apart from main) would correspond to a different section that is written independently. I could use a single file and edit it, as you intimate, but given the size of file I envision working with, having the flexibility to work on a single section and 'patch' this in would be preferable, if possible.
    – twelfth
    Commented Jul 7 at 23:44
  • 1
    OK. One way to do custom changes like this, is git merge <branch-name> --no-commit, which pauses after the stage but before the commit, and then run a custom script to do what you want, then (stage and) commit your changes. At least that would be reusable.
    – TTT
    Commented Jul 7 at 23:46
  • 1
    Maybe...but without knowing more details I'm guessing you still need to attempt the merge and modify it either way. (I assume that modification would be a similar automated script.)
    – TTT
    Commented Jul 8 at 1:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.