I'm new to git so this might sound like a silly question. I have a master branch and a feature branch.
A->B->C->D(HEAD of master)
From C I created a feature branch C->M->N->O->P->Q->R(Head of feature branch)
Now i need to merge my feature branch to the master branch but i want that the six commits that i made in my feature branch don't reflect in my master instead there should only be two commits. How can we do so?
I want the changes of both the branches to be in my master branch.
Checkout Feature branch and after your checkout run: git pull --rebase origin master
If merges are necessary, perform them, commit and run git rebase --continue
Your Feature branch will look like this: CDMNOPQR
Run: git rebase -i HEAD~6
6 is because you want to squash the last 6 commits.
First commit is "pick" All the other are "s" (for squash)
Perform git push -f
on the feature branch to push it and the new history into the repo.
Force-push is necessary due to squashing and you rewriting the git history.
Checkout your master branch and run git merge <feature-branch>
git check feature_branch
C->M->N->O->P->Q->R
to C->S
with git rebase -i C
or git rebase -i HEAD~6
git rebase master
git checkout master
git merge feature_branch
(If you've push feature_branch to remote, you also have to do
git push -f
on feature_branch to overwrite the remote feature_branch)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.