Join multiple commits from a branch

Asked

Viewed 3,350 times

3

I have the following situation: I created a branch, for which I made several commits, I pushed to github, now I intended to join these commits, which are already on github in one, so that they don’t become "junk" commits. Does anyone know how to process?

  • You want in case do a PR (Pull request) for master?

  • You will need to rebase by choosing to squash commits you no longer want (they will not be deleted but unified with your previous commits).

  • In fact you won’t actually delete commits, just abandon them and create others quite similar to the previous ones.

  • Yes, I’ve tried doing that but I didn’t get it very well I had to use the remote git rebase -i -root and when it was to push I had to force, this is not recommended because no?

2 answers

1

You need to do the following:

[1] git checkout -b nomedanovabranch

[2] git checkout nomedasuabranch

[1] This way you will create a new branch and will already switch to it

[2] This way you will switch to an existing branch

To join the commits you will need to merge the branchs, just do the following:

git pull origin NomedaBranchQueVoceQuerPegarosCommits 

Ready, that way (pull), git will automatically merge for you and take the commits from the branch you just pulled.

Then you just go up to your repository

git add . ou git add -A (Vai adicionar todos os arquivos)

git commit -m "Fazendo um merge"

git push 

I hope I’ve helped! :)

  • In this situation, when deleting the old branch, there is some problem?

  • After merging and moving up to the new branch you can delete yes.

0

If the commits you want to merge from this remote branch are latter Her commits, you need to do the squash commit on the local branch and then push to the remote branch.

See an example with the branch master. First, let’s take the last 2 commits and do the squash theirs:

git rebase -i origin/master~2 master

Now I push to the remote branch:

git push --force origin master

A warning: only do this if no one opened a branch from one of these commits you want to merge.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.