tags:

views:

118

answers:

3

I don't know if what i'm trying to do makes sense but here is the explanation:

I have some source files that are generated by a tool and then changed a little and committed. What happens is that sometimes I need to regenerate these files.

I need to do a manual merge of this new file with the one that was previously committed and pick which parts to take from the old version and which parts to take from the new version.

Is there a way to do this?

Thanks!

+4  A: 

You can create a branch like "generated_files" what you never touch but when you generate your files.

In your "master" branch you can merge the branch "generated_files".

Each time you generate new files you must commit it into the branch "generated_files" which will create a new delta from the previous generated version.

If you merge after this branch in "master", this will apply only the delta from the previous version and keep your modification.

Maybe you can use a strategy during the merge to avoid conflict.

X-Blaster
Great suggestion. This is going to work and save a lot of time. Thanks.
ivans
And now having tested this in practice, I need to say thank you again. Works great! :)
ivans
+4  A: 

Try something like:

  • git clone

  • git branch -a "temp"

  • git checkout temp

  • ... generate new files ...

  • git add .

  • git commit -m "commit text"

  • git checkout master

  • git merge temp

In essence, do your stuff in the other branch and simply merge that branch to the master branch.

Makis
+1  A: 

One way of doing it is to make use of -m option to "git checkout":

  1. Check out the base (ancestor) version, for example if you want to do a three-way merge between current version (HEAD), previous version (HEAD^) and generated file (in working directory):

    git checkout HEAD^
    

    Do not worry about warning about detached HEAD.

  2. Generate your files

  3. Use -m option of "git checkout" to merge changes from working area:

    git checkout -m @{-1} # or "git checkout -m <branch>"
    

From git checkout manpage:

-m::
--merge::

When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.

Not tested!


As a fallback you always have git merge-file low level (plumbing) command.

Jakub Narębski