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
5196
votes
45 answers

How do I squash my last N commits together?

How do I squash my last N commits together into one commit?
markdorison
  • 139,374
  • 27
  • 55
  • 71
1804
votes
15 answers

How can I merge multiple commits onto another branch as a single squashed commit?

I have a remote Git server, here is the scenario which I want to perform: For each bug/feature I create a different Git branch I keep on committing my code in that Git branch with un-official Git messages In top repository we have to do one commit…
SunnyShah
  • 28,934
  • 30
  • 90
  • 137
494
votes
8 answers

Combining multiple commits before pushing in Git

I have a bunch of commits on my local repository which are thematically similar. I'd like to combine them into a single commit before pushing up to a remote. How do I do it? I think rebase does this, but I can't make sense of the docs.
muudscope
  • 6,780
  • 4
  • 21
  • 20
179
votes
8 answers

How do you squash commits into one patch with git format-patch?

I've got eight commits on a branch that I'd like to email to some people who aren't git enlightened, yet. So far, everything I do either gives me 8 patch files, or starts giving me patch files for every commit in the branch's history, since the…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
164
votes
7 answers

How to squash commits which have merge-commit in between?

I am working on a feature branch. Made several commits. Squashed commits. Pushed changes to remote branch. Got conflicts. Merged changes from master, resolved conflicts on feature branch. git fetch origin master git merge FETCH_HEAD Resolved…
Tyr1on
  • 1,999
  • 2
  • 13
  • 20
124
votes
5 answers

Cherry-pick and squash a range of commits into a subdirectory or subtree

How can I tell cherry-pick to pick range of commits and squash it? Or in other words, apply the diff between two commits to the current state of the repository? The following does not work (cherry-pick has no --squash option): git cherry-pick…
donquixote
  • 4,877
  • 3
  • 31
  • 54
66
votes
6 answers

How can I delete all git branches which have been "Squash and Merge" via GitHub?

Ever since GitHub introduced Squash and Merge, all the cool kids at my workplace are using it when merging pull requests. Is there a way to cleanup "Squash and Merge" branches? The following command from How can I delete all git branches which have…
png
  • 5,990
  • 2
  • 25
  • 16
59
votes
3 answers

Git rebase (Merge Squash) my feature branch onto another branch

I'm looking for a git command to help me with my feature branches when they're ready to go into Master. This git command would squash all my changes on my branch into a single commit on top of master. I do this today with: git rebase…
John Hinnegan
  • 5,864
  • 2
  • 48
  • 64
57
votes
4 answers

Gitflow: Should I squash commits when merging from a release branch into master?

I am going to merge my release branch to master and I am wondering if I should squash the commits from develop into a single merge commit when merging into master. General documentations about git flow contain figures like this one from in the…
Rika
  • 671
  • 1
  • 5
  • 7
53
votes
2 answers

git merge squash and recurring conflicts

I have a git repository with master and alt branches. alt branch contains modified version of master code, and i am trying to merge changes from master to alt like this: git merge --squash master Merge results in conflict: Auto-merging…
draganHR
  • 2,578
  • 2
  • 21
  • 14
48
votes
1 answer

Git squash commits in the middle of a branch

I want to squash several commits together in the middle of a branch without modifying the commits before and after. I have : A -- B -- C -- D -- E -- F -- G | | master dev origin/master I want to…
deadbeef
  • 5,409
  • 2
  • 17
  • 47
27
votes
3 answers

What happens to tags of squashed commits?

If I have commit A tagged with tag e.g. tag-A, and then the next commit B tagged with tag-B; if I squash these 2 commits what happens to the tags? Will both be assigned to the squashed commit?
Jim
  • 3,845
  • 3
  • 22
  • 47
27
votes
8 answers

Git - squash entire branch - one line squash command

Whilst I am working on new code, I make many small commits to track my changes. My company, however, prefers each feature to be committed as a single commit. So the solution is to squash my entire (local) branch down to a single commit. How do I…
troymass
  • 1,022
  • 3
  • 11
  • 24
26
votes
4 answers

Squash commits directly on feature without rebase or merge

I've been reading a little about --squashing commits, but they all seem to be go hand in hand with a --rebase. I have a feature branch with a set of commits like this: (Feature) A --> B --> C --> D --> E --> F --> G …
Vivendi
  • 20,047
  • 25
  • 121
  • 196
23
votes
3 answers

Git - Difference between amend and squash commands

What is the difference between amend and squash commands? I tried both and found that both are doing the same for proper management.
Raju Guduri
  • 1,237
  • 1
  • 13
  • 25
1
2 3
14 15