Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge git branch without moving branch pointer

Tags:

git

I'm looking for a solution to apply a feature branch to the development branch in git without actually moving the branch pointer. Essentially, I'd like to create a single commit off of the feature branch and make sure it's pointing at the originating branch somehow (mention in the log might be enough).

I know that stacked git should offer something like that, although that would introduce new commands to the standard workflow which I'd rather avoid.

What I'm trying to achieve is some sort of feature management which allows us to apply / remove whole features, while keeping the visibility of the patch branch itself. If I do merge the branch, most commands trying to diff the change will not do what I want because the branch is already merged into develop.

I cannot really follow the upstream - sometimes there are concurrent changes which are easier to correct by getting new tag and reapplying only needed features, rather than resolving conflicts and reverting redundant features - so this way of work is not possible. On the other hand I do want to see the change, so that I can either rework it to match new version, or submit upstream at a later time.

like image 218
viraptor Avatar asked Jan 18 '26 14:01

viraptor


1 Answers

Actually, there is an easier method. The git merge command has an option --squash, which just accumulates all the changes from the branch to be merged, and adds them to the staging area.

So, you can do what you want with the following commands (when you are on master, and want to merge feature branch feature-foobar):

$ git merge --squash feature-foobar
$ git commit -m "Implemented feature: foobar"
like image 133
vhallac Avatar answered Jan 21 '26 09:01

vhallac