简体   繁体   中英

git branch cleanup with squash for a pull request

I would like to create a pull request for a branch ( uglyCommitsBranch ) that I have, but it has lots of commit messages I would like to squeeze into one commit.
To do so, I think the following steps need to happen:

git checkout master
git pull
git branch newFeature
git push origin newFeature
git checkout newFeature

Now I need to take stuff from uglyCommitsBranch and put them all into newFeature , then push to origin for code review.

What are the next commands I need to run?
I am not sure how to run rebase commands and am afraid of breaking master .

If I am currently on newFeature branch (clean branch off master ), what are the next commands to get this done?

You don't need to do that:

Simply stay in uglyCommitBranch and do an interactive rebase : clean your commits there, and the force push that branch: your pull-request (if it existed before the rebase, a PR made from that branch) will update itself.
If there was no pull request yet, you still can push --force as long as nobody else was working on uglyCommitBranch (since it is your fork).


That being said, if you want to stay in newFeature branch, then:

git merge --squash uglyCommitBranch

(As described in " How to use git merge --squash ? ")


Or since March 2016, you can leave the "commit squashing" to the main repo maintainer.
See " Github squash commits from web interface on pull request after review comments? ".

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM