2

Folks, I have a branch testFeature which i branched off master. In this branch I've made hundreds of commits and modifications, which I now would like to send out for a pull request. Trouble is, most commit messages in there are irrelevant for code review.

How can I create a new branch from testFeature with only one commit message and use that branch for the pull request to be merged into master?

Thanks!

Cmag
  • 14,946
  • 25
  • 89
  • 140
  • Note: you don't have to do that since March 2016: see http://stackoverflow.com/a/36377634/6309 – VonC Apr 02 '16 at 19:25

1 Answers1

2

Ideally you'd want to squash all the commits into just one.

For doing that you would need to identify the first commit you have made in your testFeature branch and then get the SHA of that commit's parent commit.

Once you have that you can squash your commits using git rebase.

git rebase -i <SHA of parent commit>

There you will be presented with an interactive view to squash and pick commits. This view contains commits such that the top most commit is the parent of the second commit, the second commit is the parent of the third commit and so on. Here, note what git tells you about squash: s, squash = use commit, but meld into previous commit. So ideally you will mark all the old commits as s and pick the most recent commit (if you want just one commit).

You can of course also change the final message of the squashed commit right after you move out of the interactive view for squashing and picking the commits you want.

Here's a good tutorial that might help you get started.

Hope this was what you were looking for.

gravetii
  • 9,273
  • 9
  • 56
  • 75
  • hmmm, wouldnt i need the sha of the latest commmit? why parent? – Cmag Jul 21 '14 at 17:53
  • You'd use `rebase` when you want to base your current branch on something else. So when you give the parent commit's SHA, it means you want to base all your changes on that commit. Basically, squashing commits is just a side effect of rebasing, a necessary one in your case. – gravetii Jul 21 '14 at 18:10