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

Which one is my previous commit when running interactive rebase?

When I run something like git rebase -i --rebase-merges eeb1425e0 my commits list is showed upside down, i.e., the first commit is the last and the last commit is the first: pick A Penultimate commit pick B Penult commmit pick C Latest commit #…
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
0
votes
0 answers

Git interactive rebase for commits already pushed

I'd like to squash some of my previously pushed commits in my git repository. I found a solution here, which correctly allowed me to squash many of the commits. However, after completing my interactive rebase, I get the following error: remote: To…
lcta0717
  • 402
  • 5
  • 13
0
votes
1 answer

Using git rebase, how to squash a commit into a non-previous commit

I know that using git rebase -i, I could squash a commit which will meld the commit message into the immediate previous commit. https://github.com/wprig/wprig/wiki/How-to-squash-commits But using git rebase -i, is it possible to squash a commit into…
AdeleGoldberg
  • 1,289
  • 3
  • 12
  • 28
0
votes
1 answer

How to squash the latest commit into a specific commit (which is not the previous commit)?

Suppose I am trying to rebase my current branch which has changes on top of master :- And am presented with an interactive window like this with all the new commits listed: pick A Commit message A pick B Commit message B pick C Commit message…
RamPrasadBismil
  • 579
  • 2
  • 10
  • 30
0
votes
1 answer

How do I find all commits with a certain message and squash them into the previous commit?

When I've been coding I often use git commit -am to save my work, and occasionally I'll use git commit --amend if I made a mistake in the previous commit. Recently I thought I was being clever and started combining them doing git commit…
personjerry
  • 1,045
  • 8
  • 28
0
votes
2 answers

How to unsquash pushed commit to bitbucket

I have squashed 7 commits (using git rebase -i HEAD~7) into a single commit and pushed the changes to bitbucket server. Now, I realized I need to push the 7 commits in original state. I tried git reflog and git reset --hard HEAD@{7} But can only see…
Saurabh
  • 975
  • 2
  • 12
  • 27
0
votes
0 answers

Git rebase squash producing different results to plain rebase

When I perform a git rebase -i -X theirs and squash all commits except the first, some of the resulting files are different to the most recent version of the file in the branch that I'm rebasing, whereas if I do a plain git rebase -X theirs the…
Simon Morgan
  • 2,018
  • 5
  • 23
  • 36
0
votes
0 answers

What to do with a local repo once the remote been merged

I've finished working on a branch of code, it's been deployed live and within Gitlab I've merged and squashed the branch into the master. Is there any particular reason that I might want to keep the local repository?
atamata
  • 997
  • 3
  • 14
  • 32
0
votes
1 answer

How to propagate squashed commit from master to develop and feature branches

I squashed initial commits in master to one commit using git rebase, generating a new squashed commit, but on develop branch, the commits remain as it is. How do I replace the old commits with new squashed commit in master to develop and other…
PrivateOmega
  • 2,509
  • 1
  • 17
  • 27
0
votes
1 answer

Is it safe to squash commits that include a merge commit

Can I safely squash commits where one of them is a merge commit? My commit history looks like this: I'm wondering if there will be problems or conflicts when trying to merge this squashed branch into master. I haven't pushed my branch yet so it…
polmarex
  • 1,363
  • 5
  • 19
  • 35
0
votes
1 answer

Squash/Fixup the empty commit in GIT

I accidentally pushed the empty commit into Github When I do git log I cam see 3 commits including empty commit Commit 3 : XXXX Commit 2[Empty commit]: XXXXX Commit 1 : XXXX When I do git rebase -i HEAD~3 I am getting: fatal: Needed a single…
Priyanka Anjuri
  • 381
  • 1
  • 3
  • 10
0
votes
0 answers

git squash on another branch (except master)

I am new to git squash, I created a new branch a from the master and then did a lot of changes and push to branch a. Now 8 commits on branch a and I to have squash all 3 commits to single one but when I was doing it did not work for me. Please see…
Ravindra Yadav
  • 35
  • 1
  • 10
0
votes
1 answer

Squash commits on GitHub without command-line interface

How can I squash my last X commits together into one commit using GitHub, online with just a browser, without downloading/installing/configuring git, cloning the repo, using command-line tools to do it locally, and then committing and pushing back…
WBT
  • 2,249
  • 3
  • 28
  • 40
0
votes
1 answer

merging from one feature branch to another after squashes

My team likes to have a "clean" git history, and likes commits to be squashed before I request a code review. One aspect of this workflow I'm having trouble with: I want to work on feature-branch-2 (which depends on the stuff in feature-branch-1)…
DavidC
  • 1,409
  • 10
  • 25
0
votes
1 answer

How to group commits together to create a easy patch-like workflow when working on multiple branches

I am working with localizations, a process of iterating over 40 branches, implementing approximately 40 commits on each. Some of them (let's say half), are exactly the same for almost all branches. So I started copying the commit ID (like…