Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

branch

merge

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.

like image 684
Björn Lindqvist Avatar asked Nov 18 '13 10:11

Björn Lindqvist


People also ask

How do I pull changes from another branch without merging?

Do a checkout from your current branch and pull from another branch. This pulls all the commits from the other branch into the current branch. You can work on all the changes without changes being committed to actual branch. Optionally you can commit and push if these changes needs to be tracked.

How do I move changes from one branch to another in Visual Studio?

Right-click the branch containing the changes you want and select View History.... Right-click the commit you want to cherry-pick and select Cherry-pick. Visual Studio copies the changes made in that commit into a new one on your current branch.

How do I move changes from one branch to another in IntelliJ?

You can click the Swap Branches link to change which branch is considered as a base against which you are comparing the other branch. on the toolbar . Commit and push the changes. IntelliJ IDEA will copy the entire contents of the file to the current branch.


1 Answers

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 
like image 127
guilffer Avatar answered Sep 28 '22 17:09

guilffer