How to squash 7 pushed commits into one in to 1 in git?
Asked Answered
S

2

13

I have tried multiple ways to squash my remote repo commits but didnt get it right. I want to squash them all and make it one . Below is the list of commits. Below is the summary of my pull request to upstream (which lists 7 commits). I want to list only one instead of 7.

enter image description here

Showy answered 12/5, 2018 at 2:51 Comment(1)
Possible duplicate of How to squash commits in git after they have been pushed?Mozza
A
44
git reset --soft HEAD~7
git add --all
git commit
git push --force

First, reset git index to before the commits you want to squash. Use --soft so that git only resets the index and doesn't touch your working directory. Then create a commit as usual.

Azobenzene answered 12/5, 2018 at 3:0 Comment(0)
T
18

Another way is to use squash - i other work interactive rebase

In order to do a git squash follow those steps:

# X is the number of commits you wish to squash, in your case 7
# In this interactive rebase there can be more that 7 commits if
# there was a merge in one of them
git rebase -i HEAD~X

Once you squash your commits - choose the s for squash = it will combine all the commits into a single commit.

enter image description here

Tailored answered 12/5, 2018 at 5:17 Comment(1)
Your answer is also correct. But I already had got a right answer. And there is no option to tick both the answers "Right". :)Showy

© 2022 - 2024 — McMap. All rights reserved.