Applying the changes from branch b to a, without merging or adding commits

Björn Lindqvist picture Björn Lindqvist · Nov 18, 2013 · Viewed 27.4k times · Source

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.

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 -- .

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

Anything else?

Edit: 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.

Answer

guilffer picture guilffer · Jan 20, 2017

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