shaan
shaan

Reputation: 524

git squash commits after rebased with master branch?

let us suppose my branch is featured-branch in which i'm doing development

I rebased it with master with this some commits from mater comes in my branch

How can I squash only my commits to single one , so that when I raise a pull request only my changes should appear in that PR

but since other commits comes from master they have to be in my branch but not visible in the PR

Upvotes: 1

Views: 1717

Answers (2)

Martin G
Martin G

Reputation: 18109

I prefer to always deliver one commit without exposing internal development processes:

git checkout -b delivery origin/master
git merge --squash featured-branch
git commit -m "delivery message"
git push origin master

Upvotes: 0

Aman
Aman

Reputation: 640

use git rebase -i master then editor will open change status of each commit with the following commands

# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

For example

You rebase the master then run the command git rebase -i master after the you will see some commits (suppose) like this

pick cf2cf55 C-1: Added new commit
pick c7d2f77 C-3: Allow user
pick 7db9f8d C-5: added new commit
pick 2a2e8cf C-6: Removed quick edits

The format for the above content is <command> <commit-id> <commit message>. Now you need to squash all commit into single commit then change pick command with your required command.

suppose we need to merge all commit into single commit then we use command s or squash like this

pick cf2cf55 C-1: Added new commit
s c7d2f77 C-3: Allow user
s 7db9f8d C-5: added new commit
s 2a2e8cf C-6: Removed quick edits

after save this. This will squash all other commits beside C-1. Now if you want to change commit messgae change it then save.

That's All.

Upvotes: 3

Related Questions