Git: Merge a branch but without some of the files I only need modified locally?

我的未来我决定 提交于 2019-12-22 18:23:12

问题


I have this particular scenario, which is simple really, but I don't see (so far) a similar question here.

I'm working in my own branch copied from a remote repo, And I have added my own tasks to a Capistrano Capfile. These tasks will only help Me deploy the app to my own private server, Therefore when it's time to Merge my branch with origin master, I don't want the changes in the Capfile to be pushed to the remote master repo, because, obviously, this file should remain intact over there without my personal alterations.

What's the best practice to deal with this situation?

Thanks in advance!

PS. I guess that what I'm looking for, is a way to 'Git Ignore' files exclusively for a branch. To over simplify things.


回答1:


I would suggest to branch a now branch (lets name it Local) off from your current branch (lets name it Original).

In Original, you revert the changes you made to the capfile. In Local, you continue working on your data as usual. Before it comes to remerge into the remote, you merge Local to Original and just push Original. If you do not change the local Capfile further, it should be fine, otherwise you have to (again) revert those changes (although that should result in a merge conflict anyways, so you can handle it in the merge directly).




回答2:


See the bottom of the following page: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_merge_strategies.

It describes how you can set different merge strategies with git attributes. In this case you always want the master version of your capistrano file to be in charge, not the one on your branch, e.g.

capistrano.file merge=ours

Ours refer to "our version of the file" relative to the branch you are on when doing the merge.



来源:https://stackoverflow.com/questions/9703633/git-merge-a-branch-but-without-some-of-the-files-i-only-need-modified-locally

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!