Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to merge all but one change from a branch in Git?

It's kind of like I want to cherry pick all commits from the branch except for one, but I'd like to do that in one command...

• We cut a release, which creates a branch

• The release changes the version number in all our poms, on the branch to one number, and on master to a different number

• I've committed a number of other changes to the branch and want to copy those changes back onto master

• I've merged the branch back into master, which brought the code changes but also the version number changes, creating conflicts in every pom

Is there any easy way for me to revert all the pom files to their pre-merge content and then commit that as the result of the merge?

like image 728
Graham Lea Avatar asked Nov 01 '12 02:11

Graham Lea


People also ask

How do I pull changes from another branch without merging?

You could use git checkout from the branch you want to transfer the changes to: git checkout <branch name> . That will change all files to match the version in the desired branch. Then you can commit, change, discard whatever you want.

How do I merge changes from one branch to the mainline?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch. So we need to be on the branch that we are merging into.

Does git merge change both branches?

No, merging does only affect one branch.


1 Answers

Here's what I'd suggest doing. First, do a regular merge but don't commit it:

git checkout master
git merge --no-commit <branch>

then, revert all of the pom files:

for file in $(find . -name 'pom.xml'); do git checkout HEAD "$file"; done

then you should be able to commit the final result:

git commit
like image 108
Amber Avatar answered Oct 16 '22 04:10

Amber