Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

For example, I have 10 commits in my current branch, now I want to to turn last 4 commits into one commit... I have pushed all the commit to my remote branch... now can I make my last 4 commit message into new commit message?

I want to do it, coz, my last 4 commit message was meaningless...

I tried to like this:

git rebase -i HEAD~2

it fires me a message as I have successfully rebased but later, I try to push this, it says, nothing to commit...

Can anyone help me?

1 Answer

0 votes
by (12.4k points)

You can use the command: 

git rebase -i

If you want to merge 2 commits to a recent one then you can run the command

 git rebase -i HEAD~2 

now spawn an editor listing all commits the rebase will traverse. Now to proceed with squashing change the first word of the second line from "pick" to "squash" and save your file. This will squash your 2 commits in one. 

For more information on Git, you can join git training.

To know more about git commands, check out:

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...