My program interacts with another application via a socket communication. The current public version of this application does not support a specific command while the newest trunk does. To be compatible with the current public release, I just need to re-write few lines of code. From the current point on, development must continue with this changed code, but in the future the original code should be used again.

Is it possible to make a partial change to a file temporary with Git? I could create a branch, for instance, and continue developing in this branch. However, when I merge the branch into the master, I want the changed code mentioned above to be reverted to its original code.

Note: I am well aware that I could distinguish between versions of the software, however the changes have also effect on GUI resource files which I can not affect from code other than simply loading a different resource file.

  • could you use conditional compilation? Sep 25, 2013 at 10:13

2 Answers 2


Would not solve this with git since in the end you want master to be deployable and working. So it is possible but will take time and effort.

If you can detect which version of the other application you are talking to: Just create a method which detects this and selects the right class / method / whatever you use. So duplicate the part which changes and call the right one.

That makes is easily testable, just create a test for both and you will support always both versions.

The issue here arises from an issues which is further in your application likely. Basically the socket is some kind of datasource. In that you should do handle this kind of issues. For example you could have a datasource per version of the other application or handle this in separate classes.


I have been in such a situation for most of the time I've used git. That is, I need some local changes e.g. set some paths in configuration files, that are otherwise commited to version control. Here is my workflow.

I make a commit or a couple of commits with the changes "Local Configuration", "temp", "in progress" etc. Then, when I have finished a feature, I fetch, then rebase, putting

  • new remote commits at the bottom (this happens by default in a rebase)
  • my local commits over them
  • my temporary commits on the top.

Then I can do git push HEAD~2, considering I have two temporary commits. Or better still, use the last meaningful commit's SHA.

  • I'm not as familiar as I'd like to be with git, but this sounds like a similar trick I've done with svn: 1) On the branch, make the temporary change, 2) merge that change back to the trunk, 3) undo the change in trunk 4) develop both as necessary. In svn, there's an issue where the revert committed to trunk can be merged back to the branch, but merges from the branch into trunk can happen as often as you'd like. I'm guessing this rebase trickery avoids that issue?
    – Izkata
    Sep 25, 2013 at 19:21
  • @Izkata, unfortunately I possess little knowledge of svn. So I did not understand your question - what is that problem that you talk about? In the git workflow above the central repository never sees the temporary commits - they reside only localy on the developer's computer.
    – Vorac
    Sep 26, 2013 at 8:11
  • In svn, committing them puts them on the central repository, so you can't really prevent the temporary change from being merged back into the main codebase. The steps I listed allow it to be switched back immediately, so you can merge from the branch to trunk whenever you want, without having to remember to revert that temporary change when you're done with the branch. The "problem" is that the commit on trunk that reverts the temporary change has to not be merged to the branch, else it'll be gone there, too
    – Izkata
    Sep 26, 2013 at 9:57
  • @Izkata, I understand now. The git workwflow has the advantage that the temporary commits can be added, removed or changed on demand. As far as I understand, in the SVN trick, this would require another merge-revert cycle.
    – Vorac
    Sep 26, 2013 at 10:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.