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

How to fix "Unable to unlink old *: No such file or directory"?

I have cloned a branch from a remote repository: git clone -b feature/feature1 http://..... git status On branch feature/feature1 Your branch is up to date with 'origin/feature/feature1' nothing to commit, working tree is clean Now I am…
ceth
  • 44,198
  • 62
  • 180
  • 289
5
votes
1 answer

Rewriting git history to flatten merge commits

I am moving several related projects into a monorepo, preserving every project's history. Each of the projects in question had its own repo. Also, each project's development relied heavily on --no-ff merges for reintegration of topic branches into…
ivanmoskalev
  • 2,004
  • 1
  • 16
  • 25
5
votes
4 answers

What is the difference between squashing and deleting a commit in git?

Suppose I do git rebase -i HEAD~3 and the following opens up in a text editor: pick ae27841 Commit 1 pick fd8a71e Commit 2 pick badd490 Commit 3 I want to convert these 3 commits into 1 commit so I can push that commit to my repository and then…
mjsxbo
  • 2,116
  • 3
  • 22
  • 34
5
votes
1 answer

Git: How to convert an existing `merge` to a `merge --squash`?

I performed multiple merge commits but they should have been merge --squash instead. The conflict resolution took more than a day so I can't afford to redo the merging by hand. Is there a way to convert the merge to merge --squash ?
Julien__
  • 1,962
  • 1
  • 15
  • 25
5
votes
2 answers

Git Squash sequential commits by an author to compress history

My team was working on a long running feature branch which has hundreds of commits now and now i need to merge it into master for production release. I do not want to have that many commits in that branch since many commits were done for doing bug…
Ranjan
  • 448
  • 3
  • 13
4
votes
2 answers

What is the difference between `git rebase -i HEAD~N` and `git reset --soft HEAD~N`?

We can squash the last N commits in Git. As I understand, we can squash last N commits using git rebase -i HEAD~N or git reset --soft HEAD~N. In the answers for this question (Squash my last X commits together using Git) most upvoted answer advices…
alper
  • 2,919
  • 9
  • 53
  • 102
4
votes
1 answer

How do I squash Git commits on a branch with merges

I usually never do this but this time I wound up with a feature branch that, for update purposes, got master merged into it (I usually favour rebase master on my feature branch to avoid useless merge commits). And now I want to squash all commits of…
ptpdlc
  • 2,373
  • 6
  • 22
  • 33
4
votes
1 answer

git rebase / squash - why do I need to resolve conflicts again?

I really tried looking through similar topics but I just can't seem to get a grip of the concept. I forked a repo, made some changes. Overtime, I also used git fetch upstream and git merge upstream/ a few times. Some time, there are…
some user
  • 876
  • 1
  • 12
  • 26
4
votes
3 answers

squash multiple historical commits

I have an SVN history of some 20000 commits. I moved to Git and kept the history. Now i'm at 26000 commits, and I want to squash all commits from 1 to 20000. Initial commit: a4f5d18 Migration to git: 5a42d81 HEAD: 933eff I tried checking out 20000…
Qeebrato
  • 131
  • 7
4
votes
2 answers

How to squash commits in Git?

I am trying to squash my commits and merge my branch to master as one single commit. This is what I'm trying. I switch to master branch and then i do git merge --squash And I get Automatic merge went well; stopped before committing…
Ankur Bansal
  • 51
  • 1
  • 1
  • 3
4
votes
1 answer

Find the starting point to do a rebase -i

I am working in a branch (fork of master of course) and I have a series of commits. I am interested in finding out exactly which commit is the one that is is where the branch started and is part of the master. Why do I need this? I want to squash…
Jim
  • 18,826
  • 34
  • 135
  • 254
4
votes
0 answers

Squash a Git Merge but Retain Authorship?

Is it possible to squash a merge but retain the authorship for use with git-blame?
spinlock
  • 3,737
  • 4
  • 35
  • 46
3
votes
2 answers

How can I merge all my local commit before rebase my local branch from the main?

When I work in a team and must push my local branch to the remote main, I rebase firstly my local branch to master with this simple command: git fetch && git rebase origin/main But when I do that, all my local commits are applied and conflicts…
okli
  • 33
  • 4
3
votes
0 answers

Using an interactive rebase, how do I squash some commits, including merges?

I've read a LOT of questions on here and help documents, but I can't seem to find any solid, understandable documentation that explains addresses my needs. I work on a team that's making a major code change. We forked a branch off of our 'master'…
RLH
  • 15,230
  • 22
  • 98
  • 182
3
votes
1 answer

What happens to the child branch when I have squashed the commits from parent branch and merged it into master?

My branching looks like this M1 --- M2 --- M3 --- ............. --- M50 --- M51 \ \ P1 --- P2 --- P3 --- P4 \ \ …