Skip to main content
24 events
when toggle format what by license comment
Aug 4, 2023 at 22:23 history edited Benjamin Loison CC BY-SA 4.0
Add Shell syntax highlighting
Dec 27, 2021 at 19:25 comment added Greg7000 For those who use SourceTree, I normally do all the steps described here in cmd line until 'git merge --squash HEAD@{1}' (inclusive). Then I refresh SourceTree with F5 and perform my commit via SourceTree to benefit from the ui when editing the commit message.
Nov 20, 2020 at 13:01 comment added Timo How can I create a zsh function out of it with this line git merge --squash HEAD@{1} which results in a parse error.
Nov 7, 2020 at 13:30 comment added Timo I get "Your branch is behind 'origin/master' by .. commits, and can be fast-forwarded". I then do commit or pull or merge (--ff-only) and get the same commit history as before..
Oct 20, 2020 at 5:36 comment added MING WU @LosManos I just found that we can use the command in powershell. git merge --squash 'HEAD@{1}' just put HEAD@{1} inside ' ' to make it work.
Oct 13, 2020 at 11:55 comment added Flov I would also argue that "elegant" is not the right word to use here. I would say it's slightly quicker rather than slightly more elegant since you don't spawn an editor. It's a great advantage but a hard reset also seems dangerous since you could easily lose your data.
May 6, 2019 at 5:35 comment added LosManos FYI: If you do git merge --squash HEAD@{1} and get a error: unknown switch 'c back you are probably running in powershell console. Probably easiest way to continue is to temporarily move to ordinary command shell through cmd then do your git merge --squash HEAD@{1} and then go back to powershell through leaving the command shell by exit. (I haven't bothered to figure out how to run the git merge --squash HEAD@{1} through powershell.)
Oct 23, 2018 at 7:25 comment added jpganz18 maybe is outdated? I did the reset --hard and when doing the merge --squash I get this error "fatal: You cannot combine --squash with --no-ff."
Jun 1, 2018 at 15:53 history edited ErikE CC BY-SA 4.0
added 41 characters in body
May 23, 2017 at 12:10 history edited URL Rewriter Bot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
May 22, 2016 at 9:55 comment added Mark Longair @B T: Destroyed your commit? :( I'm not sure what you mean by that. Anything that you committed you'll easily be able to get back to from git's reflog. If you had uncommitted work, but the files were staged, you should still be able to get their contents back, although that will be more work. If your work wasn't even staged, however, I'm afraid there's little that can be done; that's why the answer says up-front: "First check that git status is clean (since git reset --hard will throw away staged and unstaged changes)".
May 22, 2016 at 1:08 comment added B T Wonderful.. this destroyed my commit. -1
Mar 23, 2015 at 10:21 comment added Tobias Kienzler @PaulDraper Thanks for the info, yeah it's probably preference - and Python's "Explicit is better than implicit"
Mar 21, 2015 at 14:37 comment added Paul Draper @TobiasKienzler, you may be interested in git reflog. Git already "tags" recent commits for this purpose. git gc --prune shouldn't change that, unless you ask to expire the reflog entries. It may all be a matter of preference.
Mar 21, 2015 at 6:29 comment added Tobias Kienzler @PaulDraper well let's say due to a power outage or other interruption you cannot finish this, and next time you're in that machine out of habit you do a git pull, obtaining a few commits but not the ones you wanted to squash. I don't know if there also is a HEAD@{2} etc but with a temporary tag you don't have to remember... of course so long as you don't git gc --prune you can still retrieve your HEAD, but it's just more tedious
Aug 11, 2014 at 12:18 comment added Tobias Kienzler I'm always very reluctant when it comes to hard resets - I'd use a temporal tag instead of HEAD@{1} just to be on the safe side e.g. when your workflow is interrupted for an hour by a power outage etc.
Feb 27, 2014 at 22:21 comment added Cheezmeister Another advantage is that git merge --squash is less likely to produce merge conflicts in the face of moves/deletes/renames compared to rebasing, especially if you're merging from a local branch. (disclaimer: based on only one experience, correct me if this isn't true in the general case!)
Nov 26, 2013 at 12:35 comment added cregox Even though I appreciate the advantage of having a verbose commit message for big changes such as this, there's also a real disadvantage of this method over Chris's: doing a hard reset (git reset --hard) touches a lot more files. If you're using Unity3D, for instance, you'll appreciate less files being touched.
Nov 7, 2013 at 13:31 history edited Mark Amery CC BY-SA 3.0
[Edit removed during grace period]
Jul 8, 2013 at 15:59 comment added Mark Longair @Mark Amery: There are various reasons that I said that this is more elegant. For example, it doesn't involve unnecessarily spawning an editor and then searching and replacing for a string in the "to-do" file. Using git merge --squash is also easier to use in a script. Essentially, the reasoning was that you don't need the "interactivity" of git rebase -i at all for this.
Mar 5, 2011 at 13:43 history edited Mark Longair CC BY-SA 2.5
Add a mention of why this might be preferred to the nice `git reset --soft` answer.
Mar 4, 2011 at 10:17 history edited Mark Longair CC BY-SA 2.5
Clarify the comment
Mar 4, 2011 at 6:22 history edited Mark Longair CC BY-SA 2.5
added 30 characters in body
Mar 4, 2011 at 6:10 history answered Mark Longair CC BY-SA 2.5