git: how do I merge between branches while keeping some changesets exclusive to one branch?

前端 未结 9 572
情书的邮戳
情书的邮戳 2020-12-24 15:38

There\'s a special place in hell for people who hardcode absolute paths and database credentials into multiple random places in web applications. Sadly, before they go to he

9条回答
  •  星月不相逢
    2020-12-24 16:16

    The question is an old one, but I still have not found a good answer. Currently I am facing the same issue and below is my workaround to deal with it:

    There are two branches in my local repo: master and local_settings. Having cut off the local_settings branch from master I committed there all local paths, not tagging and not trying to remember them. During local development I am switched to the local_settings branch, so I can run an application using local paths. But when it is time to commit I stash a current state and switch to the master branch. Then I pop the stashed changeset and commit it into master. And the final step is to switch back to local_settings, merge from master and continue development. To recap: I commit into the local_settings branch only changes that will stay locally and will never go into master; and no merges from local_settings to master.

    Now let's say I need to add a "good" modification to a file with a local path added earlier, but the "good" modification is wanted in the master branch. I do my changes when the working copy is a head for local_settings, stash it and check out master. The stash keeps a changeset, that is relative to local_settings, although I am on master already. git stash pop applies the stashed changeset to the working copy and ends up having a diff relative to master, but only with the recent modification excluding the local path that had been added earlier and was not a part of the recent stashed changeset. Hence it can be committed without messing paths in the master branch. Afterwards again merge from master to local_settings.

提交回复
热议问题