Git - 不要合并删除
我有一个分支 develop
,其中包含以下文件:
- index.php
- test.php
我正在从中创建分支 release
,我在其中设置版本、进行小错误修复等,并且删除 test.php,它不会进入生产版本。然后我想将此分支合并到 develop
中,但希望将 test.php 保留在开发分支中。怎么做呢? git merge
的默认行为只是删除文件。
I've a branch develop
with files:
- index.php
- test.php
I'm creating branch release
from it, where I set versions, make small bugfixes, etc, and delete test.php which doesn't go into production release. Then I want to merge this branch into develop
but want to keep test.php in develop branch. How to do it? Default behaviour of git merge
just deletes the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1/ 我宁愿 rebase 开发分支(如果您尚未将其推送到远程存储库)位于 master 之上,以确保我的所有开发仍然与最新版本(及其所有错误修复)兼容。
如果您当前的开发确实与发布(大规模重构)不同,那么只有那时我才会考虑挑选错误修复。
2/ 如果文件需要在合并过程中保持原样,您可以设置 仅在开发分支中的
.gitattribute
文件 中合并管理器。1/ I would rather rebase develop branch (if you haven't pushed it to a remote repo yet) on top of master, to make sure all my development is still compatible with the latest release (and all its bug-fixes).
If your current development is really different from release (massive refactoring), then and only then I would consider cherry-picking the bug-fixes.
2/ If a file needs to be kept as is during a merge, you can set a merge manager in a
.gitattribute
file only in the develop branch.传统观点是,永远不要从发布分支合并到开发分支。而是使用
gitcherry-pick
将错误修复提交应用到开发分支。The conventional wisdom is that you never merge from a release branch into a development branch. Instead, apply the bugfixes commits to the development branch using
git cherry-pick
.