git - 我可以从另一个分支添加对暂存区的更改吗?

标签 git shell version-control dvcs

我有两个分支,

  • 大师
  • 新功能

新功能有一个提交,我想添加到 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/

相关文章:

php - 为什么 artisan 不处理 Composer 更新并且不返回错误消息?

linux - 难道一个文件对其他进程是不可见的吗?

git - 我怎样才能撤消 git reset --hard HEAD~1?

git - 修改后的文件不会在存储保存和存储 pop 后保持暂存状态

version-control - "non breaking change"是修订控制中的常用术语吗?

git - 如何在不复制子包代码的情况下将主要版本升级到 v2,并默认获取最新版本?

windows - “git”不被识别为内部或外部命令

git pull --rebase 通过保持本地更改来解决冲突

c - 在 Linux 上将 * 作为命令行参数传递时的奇怪行为

python - 运行 sudo 命令以在脚本中执行可执行文件