I'd like to be able to invoke some pre-processing on files before Git tries to merge them, and the post-process the merged result. The general idea here is that some files are difficult to automatically merge as-is, but can be converted to an easier form for processing. Here's my concrete use case:
I have a repository of mostly not-very-sensitive data. Within that repository, I have a little bit of encrypted sensitive data, in a file called sensitive.pgp
. I like this arrangement because I don't have to trust that my repository is being managed securely, I just have to trust the encryption and the password. The catch of course it that Git can't possibly merge encrypted text, so if sensitive.pgp
is modified in two checkouts at once, there's no merging available -- even if the changes to the clear text are easily separated. The manual work-flow is like this:
sensitive.pgp
detected.sensitive.pgp
.I'd like to tell Git to apply my pre- and post-processing before it even tries to merge, so it can handle this automatically. I can imagine lots of other scenarios with the same general pattern: Pretty much any time you have a compressed file format with a text-like underlying structure (e.g. PDF, OpenOffice, Word), for example.
Any suggestions?
We can manually resolve the merge conflict by editing the content in the bottom pane, and then saving the file using :wqa (Write and Quit all files). Once the conflict resolution is successful, the merged file will be staged for commit. git commit -m 'Merged from multiple branches' .
Use git mergetool to run one of several merge utilities to resolve merge conflicts. It is typically run after git merge. If one or more <file> parameters are given, the merge tool program will be run to resolve differences on each file (skipping those without conflicts).
You have a few options:
.gitattributes
(see git help attributes
) that decrypts the files at checkout (leaving them unencrypted in your working tree) and encrypts them before checking ingit help attributes
and the merge.<driver>.*
options in git help config
)git help mergetool
and the mergetool.<tool>.*
options in git help config
) that decrypts before invoking the real merge tool and encrypts when the real merge tool returnsYou can configure git to only apply custom filters and merge drivers to specific files, but the merge tool applies to the whole repository unless you limit it by passing file names to the git mergetool
command. You can design your custom merge tool to change its behavior depending on the name of the file being merged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With