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
21
votes
3 answers

How best to squash old commits

A developer recently left who left a ton of commits in a repo from a few months ago that are just like 'updated'. Ideally, I'd like to squash them into a single commit but I have only done this for recently commits. How would I do it for like the…
timpone
  • 19,235
  • 36
  • 121
  • 211
19
votes
2 answers

IntelliJ - How to squash local branch only

When using Git inside of IntelliJ, how do I squash all of my commits for a local branch? What settings do I use in the rebase branch window? I've tried setting the Onto to local/master and From to my branch, but then it goes and tries to merge…
NikZ
  • 650
  • 3
  • 8
  • 20
18
votes
6 answers

git interactive rebase squash into next commit

In Git I can use an interactive rebase to re-write history, this is great because in my feature branch I made a ton of commits with partially working code as I explored different refactors and ways of getting it done. I'd like to squash a lot of the…
Josh R
  • 1,970
  • 3
  • 27
  • 45
16
votes
2 answers

Git - recover intermediate commits after squash

I have squashed several commits into one commit. One of the commits before the squash included debug prints and a later commit that was squashed together with it removed those prints. Is there any way to recover them?
tba
  • 333
  • 3
  • 15
14
votes
3 answers

Branching off of squashed branches

Suppose I have the following git history: a master branch starting with commit A, a feature-1 branch branched off of A with commits B and C, and a second feature branch feature-2 that built off of commit C with commits D and E. master A …
clwainwright
  • 1,624
  • 17
  • 21
13
votes
1 answer

How to rebase branch against master after parent is squashed and committed?

I use an optimistic work-flow in Gitlab, which assumes the majority of my merge requests will be accepted without change. The flow looks like this: Submit a merge request for branch cool-feature-A Create a new branch, based on cool-feature-A,…
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
13
votes
1 answer

Rebase branch after GitHub "Squash and merge" onto master

Let's say I've developed a feature on branch1 and sent it out for code review using a GitHub Pull Request. While it's being reviewed, I do some follow-on work on branch2. branch2 -> D --> E --> F / …
danvk
  • 15,863
  • 5
  • 72
  • 116
12
votes
4 answers

How to Squash 3 commits into 1?

I'm fairly new to git, so I've been trying to figure out how to squash 3 commits into 1 so my PR can get merged. I've read a lot of docs and guides and sort of found out how to squash commits but one of my commits aren't showing up. I tried…
Kaycee
  • 123
  • 1
  • 1
  • 4
12
votes
3 answers

How to squash my git branch commits into the same branch without rebasing?

I have a local branch, we're using git-flow with Pull Requests and I'm looking to squash a few commits after receiving PR feedback. How can I squash all my commits (from PR's for example) into the same branch? I imagine it would be something…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
12
votes
1 answer

Git squash commits of renamed files (an keep history)

Backround Hi, I'm working on a local feature branch. This local branch is messed up with lots of small commits. Before pushing the branch to the remote I would like to tidy things up. For this I'd do a interactively rebase: git rebase -i No problem…
RamNow
  • 456
  • 5
  • 16
10
votes
3 answers

Git Squash and remove previous commits

Maybe I misunderstood how GIT works. I've run git rebase -i HEAD~10 and I could squash 10 commits into one. The issue is that all squashed commits are still there, and I thought they were going to be dropped after merging them all into one. Is this…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
10
votes
2 answers

xargs (or something else) without space before parameter

I would like to execute something like this (git squash): git rebase -i HEAD~3 extracting the 3 from git log: git log | blabla | xargs git rebase -i HEAD~ This does not work because xargs inserts a space after HEAD~. The problem is that I want to…
Gismo Ranas
  • 6,043
  • 3
  • 27
  • 39
9
votes
2 answers

How to squash 7 pushed commits into one in to 1 in git?

I have tried multiple ways to squash my remote repo commits but didnt get it right. I want to squash them all and make it one . Below is the list of commits. Below is the summary of my pull request to upstream (which lists 7 commits). I want to list…
A srinivas
  • 791
  • 2
  • 9
  • 25
9
votes
2 answers

github commits pile up after squash merge of pull request

I have a fork of another repo @github. did some code and issued a pull request to upstream upstream master merged with squash option now next pull request includes new code and the older commits as well. So they increasingly pile up. What can I…
Alexander T
  • 115
  • 7
8
votes
1 answer

Squashing (already pushed) commits on GitLab

I have a merge request with 5 commits, all pushed to the branch on GitLab. I'd like to squash those 5 commits into 1 -- but there are intermediate commits to the repo by other people. E.g.,in git log, you might…
user319407
  • 173
  • 1
  • 2
  • 4
1
2
3
14 15