0

When I merged my branch A to branch B and was ready to commit and push, my console told me that there were 101 commits that I will be pushing. Question is, how can I remove all these commits into just one commit so that my branch B history doesn't get flooded with unnecessary branch A 101 commit history.

Robin
  • 575
  • 2
  • 10
  • 26
  • 1
    That's call "git squash". Search with this term and you get many tutorials. – Biswapriyo Feb 16 '18 at 18:47
  • @Biswapriyo Hmm it looks like 'qit squash` use used with `git rebase` instead of git merge. I am familiar with `git rebase` and was going to use it moving forward for my merges however, is the same 'git squash` aviabale for `git merge`? – Robin Feb 16 '18 at 18:57

1 Answers1

0

You can sqash the commits of the branch A.

It can be done by using rebase.

$ git rebase -i HEAD~100 // For doing operation on latest 100 commits

This command will open a file having following details

pick #first_commit_hash# #first_commit_message#

pick #second_commit_hash# #second_commit_meesage#

... and so on

Change pick to squash for the commits to which you want to merge into the previous commit. squash will append the commit message of the squashed commit into its previous commit. If you want to discard the commit message use fixup. You can find all the option in the file opened when you run rebase command.

If you replace pick with squash for the 99 commits, at the end of rebase you will have 1 single commit which contains changes of all the 100 commits. Then you can merge this single commit in the branch B.

Community
  • 1
  • 1
Ritesh Agrawal
  • 791
  • 4
  • 7