我有两个分支,
- 大师
- 新功能
新功能有一个提交,我想添加到 master,但我想控制我想 merge 多少。
我想要为每一行添加/拒绝更改的选项。类似的我可以用 git add -p
我搜索了很多可能是我搜索了错误的术语。这似乎是很明显的任务。
最佳答案
使用 git cherry-pick
和 -n|--no-commit
选项,然后交互地选择要提交的内容:
git cherry-pick
...
-n
,--no-commit
Usually
git cherry-pick
automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit. In addition, when this option is used, your index does not have to match the HEAD commit. The cherry-pick is done against the beginning state of your index.This is useful when cherry-picking more than one commits' effect to your index in a row.
所以命令的顺序如下:
git cherry-pick -n <commitid> # merge commitid into the index and working-tree
git reset # clear the index
git add -p # selectively add merged changes to the index
或者,您可以使用 git reset -p
从暂存区移除不需要的 hunks:
git cherry-pick -n <commitid> # merge commitid into the index and working-tree
git reset -p # interactively remove from the index changes brought by commitid
关于git - 我可以从另一个分支添加对暂存区的更改吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38178112/