将更改从分支b应用于a,而不合并或添加提交 [英] Applying the changes from branch b to a, without merging or adding commits

查看:79
本文介绍了将更改从分支b应用于a,而不合并或添加提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是,我有一个分支,其中我对构建过程进行了重大改进(分支A),而在另一个分支中,我正在开发一个不相关的功能(分支B).因此,现在当我在分支B处破解时,我想提取在分支A中编写的内容,因为我想要更快,更轻松的构建.但是,我不想污染"我的分支B,只需将分支A中的更改添加到未暂存的更改中即可.

My scenario is that I have one branch in which I've made big improvements to the build process (branch A) and in another I'm working on a unrelated feature (branch B). So now when I'm hacking away at branch B, I want to pull in the stuff I wrote in branch A because I want faster and easier builds. However, I don't want to "pollute" my branch B, just add changes from branchA to unstaged changes.

我尝试过的方法(当站在branchB上时):

What I've tried (when standing on branchB):

git merge --no-commit branchA

不起作用,因为它会将您纳入合并范围.如果没有,那将是完美的.

Doesn't work because it puts you inside a merge. If it didn't, it would be perfect.

git checkout branchA -- .

不起作用,因为它会在branchA..branchB之间应用更改,而不是在master..branchA之间进行更改.

Doesn't work because it applies changes between branchA..branchB and not the changes master..branchA.

还有什么?

是的,分支A上的更改已提交.在此示例中,只有一个分支具有构建改进,但是在功能分支上我可能要应用的N个分支中有构建改进.

Yes, changes on branch A are committed. In this example there is only one branch with build improvements, but there may be up to N branches with build improvements that I want to apply while working on a feature branch.

推荐答案

我只需要做类似的事情,就可以通过将--squash添加到合并命令中来对其进行修复

I just had to do something similar and was able to fix it by adding --squash to the merge command

git merge --no-commit --squash branchA
git reset HEAD # to unstage the changes

这篇关于将更改从分支b应用于a,而不合并或添加提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆