Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Squash all my commits into one for GitHub pull request [duplicate]

I made a pull request on GitHub. Now the owner of the repository is saying to squash all the commits into one.

When I type git rebase -i Notepad opens with the following content:

noop  # Rebase 0b13622..0b13622 onto 0b13622 # # Commands: #  p, pick = use commit #  r, reword = use commit, but edit the commit message #  e, edit = use commit, but stop for amending #  s, squash = use commit, but meld into previous commit #  f, fixup = like "squash", but discard this commit's log message #  x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out 

I searched on Google but I do not understand how to do this.

like image 794
omerjerk Avatar asked Jan 26 '13 06:01

omerjerk


People also ask

How do you squash commits from a pull request?

When you select the Squash and merge option on a pull request on GitHub.com, the pull request's commits are squashed into a single commit. Instead of seeing all of a contributor's individual commits from a topic branch, the commits are combined into one commit and merged into the default branch.

Should I squash commits before pull request?

As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.


2 Answers

Just a simple addition to help someone else looking for this solution. You can pass in the number of previous commits you would like to squash. for example,

git rebase -i HEAD~3  

This will bring up the last 3 commits in the editor.

like image 102
fontno Avatar answered Sep 19 '22 18:09

fontno


ok I figured it out ... First I had to write git rebase -i xxxxxxxxxxxxxxxx where xxxxxxxxxx is the SHA of the commit upto which I've to squash. Then in Notepad I edited the first as pick and rest of all as squash. Then a new notepad window will come and there in the first line I typed the name of my new commit. And then I had to do a force push :

git push --force origin master 
like image 32
omerjerk Avatar answered Sep 20 '22 18:09

omerjerk