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
2
votes
1 answer

Squash 2 commits into 1

I have two commits locally: commit adae40c5e2b69a41447b08cc3dcb77003611fbbe Author: Me Date: Thu Mar 21 14:17:35 2019 +0000 1.0.0 commit ceaa65ea06f48dc24554a6f798aae2d668f3a43d Author: Me Date: Fri Feb 1 10:04:36 2019 +0000 first…
runnerpaul
  • 5,942
  • 8
  • 49
  • 118
2
votes
1 answer

How to use "git merge --squash" while preventing regular commits using git hooks

I would like to prevent commits to master using a local commit hook as per the answer at https://stackoverflow.com/a/40465455/329496 That works fine as I can now merge changes on feature branches into master: git merge feature_branch I actually…
simbo1905
  • 6,321
  • 5
  • 58
  • 86
2
votes
1 answer

Is there any easy way to get one commit per feature in master instead of rebase with squash

I have created a feature branch against master branch 2 months back. Updated the feature branch several times in the meanwhile and almost each time I had some conflicts while merging. Fixed those and pushed to feature branch. Now the problem is, in…
Niranjan Kumar
  • 1,438
  • 1
  • 12
  • 29
2
votes
1 answer

Squash commits before hash

I have forked a quick-start repo and built an app on top of it. The quick-start repo contained ~30 commits. The last commit of their repo is, say, abcde and first commit of mine is, say, fghij. How can I squash all of the commits, from first to…
dczajkowski
  • 163
  • 2
  • 11
2
votes
2 answers

Does squashing commits have an impact on mergability?

I am reading about the pros and cons of squashing commits in Git before crafting a pull request. What I did not find information about is, whether a pull request with squashed commits is more or less likely to turn into a merge conflict if other…
Matthias Ronge
  • 9,403
  • 7
  • 47
  • 63
2
votes
3 answers

How do I squash commits when I have merged with dev in between?

I have worked on a feature branch for a few days and it's now ready to merge into dev. While working on this feature, I have merged with dev to receive a patch. My history looks like this: * E (feature1) * D:merge with dev | \ * C * B:patch (dev) …
lfk
  • 2,423
  • 6
  • 29
  • 46
2
votes
1 answer

What is the best practice to squash pushed Git commits

So far, I have been doing interactive git rebasing fairly often on either: unpushed work, or on pushed work that I knew for sure I was the only one to work on. I know squashing commits and overall rewriting history can be tricky when it gets to…
ptpdlc
  • 2,373
  • 6
  • 22
  • 33
2
votes
0 answers

Git Squash Not Working

I am trying to use git rebase -i HEAD~10 and this page is shown: As seen on the picture, I am trying to squash 6 commits into one. However, when I save the file, I am not shown another editor for me to give a new commit message for the squashed…
gogofan
  • 533
  • 1
  • 10
  • 20
2
votes
1 answer

Git rebase interactive error

I want to merge my branch (lets call it my_branch) to master. It has 1 file showing up as a merge conflict on my pull request on github.com . Before rebasing I want to squash my commits (11 commits). So I did something like this: # On master git…
letsc
  • 2,515
  • 5
  • 35
  • 54
2
votes
2 answers

GIT - cannot squash commits : fatal: Needed a single revision

I'm trying to squash my last 2 commits with git. In this example I have created a branch from another branch called develop and I have 3 new commits, this is the git log : commit a350cf6071db1bcaa2a37710a61508565a34d917 Author: tibbus Date: Tue…
Tiberiu Popescu
  • 4,486
  • 2
  • 26
  • 38
2
votes
1 answer

can we squash the latest commit to a specific previous commit?

For example, if we want to squash the commit at HEAD into commit HEAD~4, we have an option by which we can do so by resetting commits from HEAD to HEAD~3 building a temporary commit with same changes as our old HEAD(say, temp) stashing other…
srishabh
  • 141
  • 9
2
votes
0 answers

Git squashed merge with conflicts missing commit message content

When I do a git merge --squash that results in conflicts, the pre-defined commit message content from Git contains only the conflicts information but not the summary of the squashed commits. λ git merge --squash…
Niklas R
  • 16,299
  • 28
  • 108
  • 203
1
vote
1 answer

Git rebase branch onto squash merge

I did a mess with my features branches. What I had: master: A - B \ branch1: E - F \ branch2: G - H And then I squashed and merge branch1 to the main Added a few commits on the…
Chana Drori
  • 159
  • 1
  • 1
  • 10
1
vote
0 answers

Squashing commits not in series using git rebase

I have multiple commits done on a branch for a C project and would like to squash them into just two commits. Commit 1 - should have only the changes to the actual functionality source code Commit 2 - should have the changes to the test code…
Engineer999
  • 3,683
  • 6
  • 33
  • 71
1
vote
1 answer

Squash git commits by author

I have a repository to which several (3) authors contributed commits to the same branch of the repo. I want to merge it to the repository from which it was forked, but the admin of that repository asked me to squash the commits by author before they…
John
  • 465
  • 1
  • 6
  • 13