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

Git squash N-consecutive commits in the middle of the branch history

Let's say I have several consecutive commits, we name them A0..A99 for simplicity, pushed by the same author to the main branch: these commits are not the last commits pushed to the main branch as other commits were pushed on top of those by other…
smn.tino
  • 2,272
  • 4
  • 32
  • 41
0
votes
0 answers

Can't fully squash commits

The commit Paises ISO 3166-1 all modify the same files and leave them in the same state. Is there any way to make it so there's only 1 commit Paises ISO 3166-1 on the blue line right before the branches? I've tried git rebase -i c5d892b4 but the…
Daviid
  • 630
  • 4
  • 17
0
votes
1 answer

squash commits in git and remove "ugly" merge message

I am trying to squash 2 commits and remove merge part, but have some problems. I have branch main and featureBranch. In my terminal I do: git checkout main git merge --squash featureBranch git push But nothing really happens. I am in the project…
Kratos
  • 681
  • 1
  • 13
  • 30
0
votes
0 answers

How to fetch changes from a forked repository which is a subtree

So I have an issue wherein I forked Repository A to create Repository B. Then I added Repository B into a subdirectory of Repository C via the subtree command as follows: git subtree add --prefix={SubdirectoryForRepositoryC} /remote-name…
user3684314
  • 707
  • 11
  • 31
0
votes
0 answers

Using squash-merge with git subtree

I'm try ing to set up git subtrees ti mage shared utils and TS types in a couple repos. I'm confused on how git handles squash-merges in subtrees and right now I'm runnning into errors. Let's say I have a repo project and have set up another repo…
0
votes
0 answers

Delete/Squash old commits while keeping the changes that they introduced

I'm trying to delete/squash a bunch of old commits that I don't want on my git history which were just made to put together code from multiple locations that were not using git (local folders from other programmers) This is how the actual git…
Girog
  • 1
  • 2
0
votes
1 answer

Git: remove some commits from a branch

Let's say I have, in a given working branch, a history of commits that looks like the below: commithash1 [task-a] lorem ipsum commithash2 [task-a] dolor sit amet commithash3 [task-b] consectetur adipiscing commithash4 [task-c] elit se do commithash5…
darksoulsong
  • 13,988
  • 14
  • 47
  • 90
0
votes
1 answer

Squashing commits gone wrong

Say I have pushed two commits and I and try to squash them. Instead of doing git rebase -i HEAD~2 - I accidentally do git rebase -i HEAD~3 Here the 3rd last commit is from someone else but it would show up in my PR and say "Other author and R11G…
R11G
  • 1,941
  • 8
  • 26
  • 37
0
votes
1 answer

Undo git commit message in 2 different branches (develop and feature) after git push

do not want to break anything in the master branch. I forked a develop branch through below commands git checkout develop git pull upstream develop # pull the updates locally based on the git push origin develop # sync your local develop branch…
0
votes
1 answer

How Can I git squash commit after PR completed?

In our projects, We use policy squash merge for merging and release our project when merge release branch to master branch. one of my co-worker use no fast-forward merge and put all develop's history commits in master's history commit. I search the…
Alex
  • 31
  • 4
0
votes
1 answer

bash script that squashes commits with same name in a row

I want to create bash script that squashes commits with same name in a row. The user should be able to enter the commit number between which it will search for commit names and if it finds 2 similar names in a row it should merge the…
0
votes
1 answer

How to work on a new git branch while previous branch waits for merge

First, I am sorry to ask such question because I am sure it is a straightforward issue, still I found no solution an no way to understand what I am doing wrong. Some people asked almost exactly the same question (except the squash part) and the…
haltux
  • 61
  • 4
0
votes
1 answer

Combine 2 commits that are NOT the last 2 commits on my branch

I have to following 4 commits: #Commit4 #Commit3 #Commit2 #Commit1 After making commits 3 and 4 I realized my first 2 commits really should be a single commit like so: #Commit4 #Commit3 #Commit1_and_commit2 Is an interactive rebase recommended for…
RayLoveless
  • 19,880
  • 21
  • 76
  • 94
0
votes
1 answer

Documentation of Default Target of "git merge --squash"

Sometimes I squash a bunch of commits together. Usually my commands follow this pattern: git reset --hard HEAD~4 git merge --squash HEAD@{1} git commit Today, though, at step 2, I got distracted by something (squirrel? Slack? Facebook?) and I…
Kirby
  • 15,127
  • 10
  • 89
  • 104
0
votes
1 answer

GitHub Pull Request: Squash before merge without fast-forward

GitHub offers three options to merge PRs: Merge pull request: No fast-forward merge. Squash and merge: Squash commits and perform fast-forward merge. Rebase and merge: Rebases all commits onto the other one. Is it somehow possible to automatically…
Yannic
  • 698
  • 8
  • 22