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

How to squash a commit made in the GitHub website?

I did a little editing in a file on my GitHub repository through the website and then committed the changes. It's not like changing a file, committing and then pushing it to the origin, I did it directly by going to the website. Now there are two…
3
votes
2 answers

Is it possible to squash Git commits after a PR has been submitted and changes then committed?

We're learning Git and we're using GitHub as our hosting site. We all fork the upstream repo and PR our commits up to upstream to get our changes in. We're trying to learn how to squish our commits to keep the upstream commit history nice and…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
3
votes
2 answers

How to squash merge multiple commits from branch to master in a single commit using SmartGIT?

I have a branch called work_in_progress which is used to debug and test code with many small commits. All of them have redundant commit messages. When I'm finished I want to merge squash to master branch. Usually this is one single command when…
FrozenTarzan
  • 834
  • 10
  • 30
3
votes
1 answer

Merge + Squash does not change MERGE_HEAD?

We are working in a team where we had local branches with everyone working their own branch and we had committed few branches and merged with --squash. Now we have to delete those branches that are merged in in 'staging' branch. The issue is when we…
Raza Hussain
  • 762
  • 8
  • 18
2
votes
1 answer

How to have one branch with full history and one branch with squashed history?

I have are requirement that the main branch has only one (potentially big) commit per issue ID. However, to confirm to the best practice of small commits, I also need to create and keep(!) multiple small commits per issue ID. I have already found an…
Marco Eckstein
  • 4,448
  • 4
  • 37
  • 48
2
votes
2 answers

Squashing first few dozens of git commits that contain merge commits

I have an existing repository that has root R, then a few dozens of commits including multiple merges, up to X, and then linear history up to Y. I'd like to squash everything from R to X into a single commit and force push it. How can I do it…
Xilexio
  • 1,178
  • 19
  • 40
2
votes
0 answers

Cannot squash merge in GitHub Desktop

When trying to squash merge 3 commits in GitHub Desktop, I was warned with the following error message: Unable to squash. Squashing replays all commits up to the last one required for the squash. A merge commit cannot exist among those commits. As…
Paris Geis
  • 31
  • 6
2
votes
2 answers

Checkout to one of squashed commits

In a repository with squash-merge practice, can I go to the state of the repository in one of the squashed commits? For the example below, I want to find commit m1 by checking out commit r1. m1 - m2 ------- m3 <- master (r1, r2, and r3 are…
Erdem Tuna
  • 500
  • 4
  • 18
2
votes
0 answers

Visual Studio: squash intermediate commits

I can squash the last commits easily with with Visual Studio. However, if I don't select the latest commit, squash commits menu entry is grayed. Is there a solution with visual Studio to squash intermediate commits?
Kiruahxh
  • 1,276
  • 13
  • 30
2
votes
2 answers

Git interactive rebase did not delete my other commits

I have some commits in my current branch. I want to convert those all commits into one commit and delete all those commits. So I have used the following commands git rebase -i HEAD~9 Edited all commits to Squash except the oldest one to Pick and…
smnth90
  • 750
  • 5
  • 14
2
votes
1 answer

How to combine multiple historic commits into one while not touching the recent ones?

I want to combine multiple historic commits together, while not touching the recent ones, as shown in the picture, I want to only combine the 2-4 commits together. After reading relevant answers and posts, I have tried git rebase - i HEAD~5 and fix…
LWang
  • 95
  • 1
  • 10
2
votes
1 answer

Git squash commits with same commit message

Is there a simple Git command to squash all commits with the same commit message to one commit in a new branch? A simple command seems to me: git merge --squash BRANCH_WITH_SAME_COMMIT_MESSAGES The problem is that I created that branch from the…
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
2
votes
3 answers

Is there an easy way to squash many commits in git?

I have the following issue: I have many commits that need to be squashed (several thousand, we had a runaway script). Those commits are in groups between 40 to 200. Using git rebase -i is not feasible since it would involve too much labor. We have a…
Pingger Shikkoken
  • 394
  • 1
  • 5
  • 15
2
votes
3 answers

Git alias to squash feature-branch commits

I'm frequently squashing all the commits on a feature branch before committing to master. Here's what I do currently: git checkout master git merge --squash {branch} git commit -m "{feature_summary}" Is there an git alias I can use to do this? The…
Maximilian
  • 7,512
  • 3
  • 50
  • 63
2
votes
2 answers

git rebase squash messes up branches history

I have a git repository with a long history and various branches, which have been merged into master. However, the first commits simply stem from the first one, without any branching. I would like to squash together some of these first commits. To…
francesco
  • 7,189
  • 7
  • 22
  • 49