Questions tagged [git-squash]

git squash is the command used to rewrite git history before it is pushed to the remote.

GIT doesn't provide a modify history tool but provides measures to do so if the need arises. One can use git rebase in the interactive mode (git rebase -i) to achieve this with the parent of the last commit that you want to edit as the argument.

This is where git would present a text editor with the commits between this commit and the head listed in the reverse order. You can use "pick", "edit" or "squash" a commit.

squash specifically tells git to apply the commits in question and the commit before them in order and makes you to merge the commit messages.

This is a good way to keep the commit history on the remote cleaner while taking advantages of the version control to checkpoint your local code repo.

git rebase rewrites the history of the commits between parent mentioned above and head. Use with caution! It is not recommended to use this with the code that is already pushed to the remote.

216 questions
3
votes
2 answers

How to squash several commits to another branch?

I will develop my app in branch dev and provide the "best so far" (a release on GitHub) on a branch public. The branch dev will have commits c964dea, 06cf8ee, 396b4a3 and 9be7fdb. I would like to squash them into a single commit on branch public…
WoJ
  • 27,165
  • 48
  • 180
  • 345
3
votes
1 answer

How to squash commits that contain a merge commit

Is there a way to squash commits that have a merge commit? I am able to squash when there is not any merge commits but I don't know how to do it when there is one. Like these two commits.
Burak Akyalçın
  • 302
  • 5
  • 26
3
votes
1 answer

How to divide commits into multiple squashes

I need some help with squashing commits in GitHub. I have about 30 commits and I want to squash the first 10 commits into one single squashed commit and another 10 commits into another squashed commit. I have used git rebase -i HEAD~10 and squashed…
3
votes
1 answer

Keep commits in feature branch after squash merge to master

Goal: After a new feature has been developed in feature-branch, I want to "merge" it to master with a single commit in master's commit history. However, I would still like to be able to access the original commit messages for each changed line, even…
3
votes
2 answers

Git squash changes are being rejected by the remote repository

I am trying to squash 3 commits. I clone the repository I checkout the branch with the commits I want to squash I run 'git rebase -i HEAD~3' I 'pick' the top commit and I 'squash the second and third one. This is all fine. On my local branch the…
Lieuwe
  • 1,734
  • 2
  • 27
  • 41
3
votes
1 answer

Git conflicts after squash merge

I have a master branch and a dev branch. e.g. master: A--B--C dev: A--B--C--D--E then I want to release D and E, so I create a release-1.0 branch from master, squash merge dev to release-1.0, so release-1.0: A--B--C--F(D&E) after I release, I…
yukuan
  • 521
  • 5
  • 18
3
votes
1 answer

Rebase onto Rebase/Squash

This is a common situation I come across, and I'm looking for a clean solution. Do some work on a git branch (my-first-work) Push up to github Start a new branch (some-further-work), based on top of the work my-first-work Unspecified amount of…
deworde
  • 2,679
  • 5
  • 32
  • 60
3
votes
1 answer

How to make sure fixup commits are not merged into master branch

I use git commit --fixup (or --squash) a lot, especially during code reviews. Obviously these commits should eventually disappear after a git rebase --autosquash but it worries me that I might forget to rebase and merge these commits into…
3
votes
1 answer

Why error switching branches after squashing? Nothing to commit

I just squashed my remote commits, then forced-pushed them to the remote. A git status shows no changes. Why then would I get this error when trying to checkout the develop branch? error: Your local changes to the following files would be…
Bob Horn
  • 33,387
  • 34
  • 113
  • 219
3
votes
3 answers

git annotate a squashed commit

I've always been sceptical about 'squashing' or rewriting history, and now I'm just about convinced that I should ban this practice from the repos I manage. But maybe somebody can answer this, and save the day for my squash-championing colleagues. I…
Michael Scheper
  • 6,514
  • 7
  • 63
  • 76
3
votes
1 answer

Cherry Pick a Squashed Commit

I have two main branches, staging and master. I have a few commits and I have pushed those changes to a branch say xyz whose base branch is staging and have created a pull request for staging branch. All these commits has been squashed into a single…
Nidhin S G
  • 1,685
  • 2
  • 15
  • 45
3
votes
3 answers

Is it safe to squash commits from other branch

There are two branches master and feature. The development goes in feature branch and there multiple commits done in that branch, but in between them there were several merges with master branch, so the log for feature branch is for example…
marknorkin
  • 3,904
  • 10
  • 46
  • 82
3
votes
1 answer

Squash hundreds of old commits on origin

I made a silly mistake and am not sure the best way to resolve it. Here's what I did: Created a web project based on a boilerplate. Removed .git to remove all history (about 500 commits) before making my initial commit Several months and about 200…
Tauren
  • 26,795
  • 42
  • 131
  • 167
3
votes
1 answer

How to reset rebase squash?

How do I reset git squash? I am using PhpStorm. I squashed commits from last 14 days of work. The commit "HEAD DEV Refactor gulp file" has 50+ squashed commits inside. How do I show / unsquash them again?
Michal
  • 4,952
  • 8
  • 30
  • 63
3
votes
3 answers

git rebase squash take second message (like fixup)

Suppose I have some commits: bug due to function1 bug due to function2 ... other commits and I would like to squash commits 1 and 2 together, keeping only the message of the second commit, then I would use git rebase -i, edit to: pick…
Chris Maes
  • 35,025
  • 12
  • 111
  • 136