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

Git - How to squash the last commit with ANY other one

Consider the following series of commits on the local branch: 5 Correction of something meaningless, again ! 4 Business correction n°3 3 Correction of something meaningless 2 Business correction n°2 1 Business correction n°1 I want to squash 5 with…
Flyout91
  • 782
  • 10
  • 31
1
vote
1 answer

Git "autosquash" without squashing?

Any way to perform an "autosquash" without actually squshing the commits (i.e. just reorder commits marked with --fixup s.t. I can fix the merge conflicts prior to code review)?
User1291
  • 7,664
  • 8
  • 51
  • 108
1
vote
0 answers

How to include SHA and timestamp of original commits in the commit message of a squashed commit?

I understand that changing anything in a commit is going to change its SHA. This question is NOT about preserving the SHA of a commit. When I do a git rebase -i and squash a bunch of commits using pick and squash, the resultant commit…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
1
vote
2 answers

squashing commits all the way to the initial leaves 2 commits

I am learning git and trying out squashing. I'd like to squash all commits on the master and be left only with initial one. For example, my commit history looks like this: 2c825e339b60702b7b48c2ea022e473341d89a7d (HEAD -> master) another…
sanjihan
  • 5,592
  • 11
  • 54
  • 119
1
vote
1 answer

Squashing history commits in a pushed branch

Background I have a GitHub project I'm currently working on and at the same time I'm learning Git. Today I've read about squashing with rebase command and wanted to try it on some commits that I've pushed a few days ago. The commits I want to work…
1
vote
1 answer

Is there a way to non-interactively rebase and squash everything in my feature branch?

Sometimes I have a bunch of small commits in a feature branch, and I'd like to just squash them all together, but not merge into the parent branch yet. I know I can (in this example parent branch is master): git rebase -i master and then tag all of…
Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
1
vote
1 answer

Git Interactive Rebase Shows commits from master branch

I am trying to squash a few commits from my branch before merging a pull request. When doing git log I can scroll down to the commits I want to squash (14 commits back). Doing git rebase -i HEAD~14 shows my comments and also commits made onto…
d1596
  • 1,187
  • 3
  • 11
  • 25
1
vote
2 answers

Squash frequent merge history from main branch into one

For example, I just merged master branch to my feature branch. Then someone pushed new stuff on master. So I merged again to keep up. And then someone pushed again... I merge again. How do I squash the previous merges so that two merge actions is…
flm8620
  • 1,411
  • 11
  • 15
1
vote
2 answers

How does git handle a squash commit after a fixup commit?

I'm working with a branch with a fairly large number of commits and would like to do an interactive rebase to condense it into fewer commits before merging to master. In order to avoid weird conflicts, I'm trying to maintain a certain order to the…
1
vote
1 answer

why does my repo is showing behind the upstream after squash commit?

I have forked a repo and I commit and push new changes and merged changes came from pull upstream after doing squash. So isn't is supposed to show The branch is x commits ahead of upstream:master" Instead its showing The branch is x commits ahead…
A srinivas
  • 791
  • 2
  • 9
  • 25
1
vote
1 answer

How to perform sporadic merging of one branch into another

I develop on a branch dev and every couple of weeks want to merge the current state into a branch staging. It seems I didn't think this through enough, because now that I want to do this for the second time I get a conflict, since the last common…
Arne
  • 17,706
  • 5
  • 83
  • 99
1
vote
1 answer

Git rebasing (squash) after creating new branch

Suppose I have Commit history as follows: a -- b -- c <-- Branch1 \ d -- e <-- Branch2 Now I checkout to branch1 and squash commits b and c into x. I expected something like this to happen. a -- x …
Raman
  • 2,735
  • 1
  • 26
  • 46
1
vote
2 answers

Git squash commits after pulling other commits from master branch

Suppose I have the following commits on my local branch A, which I then push to the remote branch. commit 1 commit 2 commit 3 commit 4 Now, I pull from the remote master, and the commit history looks like this - //From branch A commit 1 commit…
ankit0311
  • 735
  • 3
  • 10
  • 20
1
vote
1 answer

Keeping clean git branches, but not causing conflicts in the meantime

I've been working on getting my team's git workflow down and succinct. Our team uses master,staging, and development branches for our build servers. When a new task/feature is being worked on, we will begin by creating our feature branch from…
Neurax
  • 3,657
  • 2
  • 13
  • 18
1
vote
1 answer

Git: Push differences between two branches of different repos as a single commit to another repo

I made a fork of my public Github repo on a private Gitlab repo. I made several commits in a single branch of the fork and want to push all these changes (differences between public repo branch and private repo branch) as a single commit to the…
Henrix
  • 53
  • 9