如何在没有一些文件的情况下将一个分支合并到另一个分支?

How to merge one branch to another without some files?

我有两个分支 - development 和 master。我还使用 Catch2 框架进行单元测试。 Catch2 在开发分支上,但在发布要掌握的版本时,我不希望这些文件去那里。

是否有允许我 "lock" 一个分支上的一些文件的命令? 假设它看起来像这样: 发展 - 源代码 - 单元测试代码

合并

硕士 - 源代码

您使用 cherry-pick 命令从一个分支获取单个提交。

如果您想要的更改不在单个提交中,则使用此处显示的方法 split the commit into individual commits。粗略地说,您使用 git rebase -i 获取要编辑的原始提交,然后使用 git reset HEAD^ 有选择地还原更改,然后 git commit 将该位作为历史记录中的新提交提交。

There is another nice method here 在 Red Hat Magazine 中,他们使用 git add --patchgit add --interactive,如果您想将不同的更改拆分为单个文件(在该页面中搜索 "split")。

拆分更改后,您现在可以只挑选您想要的更改。

使用git checkout --patch <branch> <file> 确保你在 master 分支上。