Squash Commits in Git Desktop
Solution 1
In order to do a git squash follow those steps:
// X is the number of commits you wish to squash, in your case 6
git rebase -i HEAD~X
Once you squash your commits - choose the s
for squash = it will combine all the commits into a single commit.
You also have the --root flag in case you need it
try: git rebase -i --root
--root
Rebase all commits reachable from <branch>, instead of limiting them with
an <upstream>.
This allows you to rebase the root commit(s) on a branch.
When used with --onto, it will skip changes already contained in `<newbase>`
(instead of `<upstream>`) whereas without --onto it will operate on every
change. When used together with both --onto and --preserve-merges, all root
commits will be rewritten to have `<newbase>` as parent instead.`
Solution 2
Is there a way to do this via GitHub desktop that might make more sense?
Starting with version 2.9 there is now a way to squash commits in GitHub Desktop.
Here are 2 of the convenient ways to do this.
- Select multiple commits in "History" tab (using Ctrl or Shift keys), right click on one of the selected commits and select "Squash 2 commits...".
- When merging a branch into another branch click on the arrow on the right to submit button and select "Squash and merge".
Solution 3
This post from Thoughtbot might help you get through it via command line. It's probably better to know exactly what you're doing than to rely on a GUI tool for Git. It will benefit you in the long run.
https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history
Shwheelz
Updated on June 09, 2022Comments
-
Shwheelz almost 2 years
I'm trying to squash 6 commits into a single commit using a branch that I already pushed to GitHub.
I tried to do this via command line, but I keep receiving no-op instead of the commits for that branch.
Is there a way to do this via GitHub desktop that might make more sense?
Please provide step by step if possible;
I'm new to using GitHub for collaborative purposes and my knowledge doesn't span very far past git add, commit, and push.
-
Shwheelz over 8 yearsMaybe this will sound silly, but when I try to type 's' in the command line on the vim screen, it just overwrites the first 'p' in 'pick'. How do I actually pass it the command? I also tried :s but it yields the message "E33: No previous substitute regular expression"
-
CodeWizard over 8 yearsYou cant squash the first one, if you want to squash it set the X to 7
-
Shwheelz over 8 yearsSo if I change "pick" to "squash" for the 5 commits after the first one, how do I "save" that with vim?
-
CodeWizard over 8 yearsyep. exactly. squash the first X and then save. you will see rebase message in the console
-
Shwheelz over 8 yearsI don't think you understood my question. I'm trying to squash the commits... what exactly do I need to do to accomplish that? Vim keeps giving me the error message listed above when I try to save
-
Shwheelz over 8 yearsI ended up having to use 's' instead of 'squash'. Not sure why that fixed the problem. Marking the questions as answered, but I've got one more roadbloack. What's the easiest way to push this squash to GitHub?
-
CodeWizard over 8 yearsyou need to overwrite the code in github:
git push -f origin <branch>
the -f is to force the update of the branch since you did a rebase -
holms over 3 yearsI'm getting "cannot squash without previous commit" whatever this means.. I want to squash all commits in that list and set new commit messages, how can I do that?