gitgithubvisual-studio-code

Visual Studio Code: I want to do "git merge --squash" from VS Code


I have a master branch that is the production branch, and I create several other branches for fixes and defects. I make several changes in those branches, and I commit many times in those branches. As per the policy, I have to create a single commit for a defect in the master branch for a fix, but when I merge my changes to the master branch - all the commits are also merged, and this is reflected in the Git history.

I want to know if there is a feature in VS Code to squash merge commits from my defect branch to the master branch, so that I can just create a single commit in the master branch, and force push.

I know how to do this in Git Bash, but is there an alternative in VS Code that I am not aware of?


Solution

  • The git graph extension has this feature - Usage example

    The recording above assumes that the current checked-out branch is the branch you want to merge into (e.g. in the recording that branch is called master), and the branch that we want to merge is the branch that gets right-clicked (e.g. in the recording that branch is called fix_branch).

    Since this is a squash merge, the fix_branch doesn't really get merged into master, a single squash-merge commit gets created on top of master. This new commit has just the previous commit marked as a parent, rather than the usual 2-parent commit that we get in regular non-squash merges.