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
1
vote
3 answers

How to correct bug in merge - squash fix commit to merge commit

this should be probably very easy, but I am not able to solve it out. I introduced bug in the merge, and than I corrected it in additional commit. I would like to squash the "bug fix" commit to the merge commit so it looks like the bug was never…
Jakub Znamenáček
  • 766
  • 1
  • 4
  • 18
1
vote
0 answers

Validate commit message contains Jira Ticket Number when squash merge from GitHub webUI

When doing a squash merge, following a successful Pull Request, on github I would like to validate that the squash merge commit message contains a Jira ticket number. If it does not the squash merge should fail until a proper commit message is…
1
vote
1 answer

Avoid old commits after squashing into a branch

I have 2 branches. main and deploy. I keep committing changes to the main branch, and when it's the time to deploy, I raise a PR to deploy from main and squash all commits for a cleaner commit history in the deploy branch, it helps to track changes…
user3515181
  • 49
  • 1
  • 8
1
vote
1 answer

Squash merging in git keeps including previously-merged branches

I'm using Github, with branches for development, live and various feature & bug branches. When I merge a feature or bugfix into development, I typically do a squash merge (usually through the GH website, although it's equivalent to git merge…
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
1
vote
2 answers

how to automatically clean merge-squashed branches?

I always prefer to rebase -i my changes locally and leave a very clean and useful commit history for my feature branches. This also have the benefit of being able to prune local/remote branches after they are merged into main (or master) with total…
Gabriel
  • 177
  • 13
1
vote
1 answer

Get rid of several bad commits

I have repo where I don't track .gitignore, someone committed node_modules folder and later we decided to untrack it. Now same person(new to git) committed '.gitignore' for few commits before untracking it again. Now we have situation where if we…
chadedgar
  • 111
  • 1
  • 6
1
vote
0 answers

How to merge Feature, Develop and Main without leaving branches ahead/behind (github)

We have an issue that whenever we merge into main, develop and main continue to be out of sync. We have: Main - production Develop stage Feature branches (temporary) At the start of this, Main and Develop are completely matching (no ahead or…
iamonkey
  • 121
  • 1
  • 4
1
vote
0 answers

How to squash commits that contain merge commits without re-resolving conflicts?

I've been working on a long running branch and I've been pulling another branch (develop) into my branch every so often. I've also been making small WIP (Work in Progress) commits as I go along. I'd like to rebase/squash all the WIP commits…
jonathanbell
  • 2,507
  • 5
  • 23
  • 40
1
vote
3 answers

Do I have to clean password from branch commit history if I do squash merge?

I accidentally committed a password to a feature branch and synced that branch to remote. I tried to clean the branch commit history with bfg without success and with git-filter-repo I'm having other problems. I now committed the settings file…
Mathias Rönnlund
  • 4,078
  • 7
  • 43
  • 96
1
vote
1 answer

Squash many pushed commits before merging into main

In a big refactoring branch, I was forced to do commits due to some git flaw (git loses track/history of moved files if too much of the content changes before committing), which left the repository with commits that are not "buildable". To be on the…
Robin Holenweger
  • 321
  • 3
  • 14
1
vote
1 answer

git history screwed up

I was trying to do rebase to combine the commits into one single commit, but I ended up writing more commits and now its all screwed up big time. Here is the tree: on running git status, I get On branch master Your branch is up to date with…
harry123
  • 760
  • 1
  • 7
  • 22
1
vote
1 answer

different git history in develop and master due to git squash

We follow the Gitflow pattern and have develop, release and master branches. We merge the feature branches into develop. We checkout the release branch from develop and merge into the master during the release time. We had set the squash and merge…
ravi
  • 133
  • 12
1
vote
0 answers

Squash for already pushed commits

I am trying to squash 9 commits of my branch, and for this, I ran this command: git rebase -i HEAD~9 After then, it showed editor on terminal. Then, I edited the first one as pick , and rest one as squash. Then, to save it, I…
Harshita
  • 372
  • 4
  • 16
1
vote
1 answer

Can I git merge --squash a local branch to remove sensitive information?

I am developing an API client, and being a good git user I did all my work on a feature branch. I made dozens of commits to my local branch but have not pushed it anywhere. I am now ready to merge my local branch into master However during initial…
Josh
  • 10,961
  • 11
  • 65
  • 108
1
vote
1 answer

How can I squash commits I've already merged?

I've just merged a PR for my GitHub repository. But - I want to squash the different commits that have gone into that PR. I thought I would be able to do it by simply rebase -i ^ but that doesn't do what I expected…
einpoklum
  • 118,144
  • 57
  • 340
  • 684