5

Hi I have a branch stable which contains merged commits of other branches. The structure is as follows:

Commit History:

Commit 1 - Branch 1 commit 1 ------------- Hash Code 1
Commit 2 - Branch 2 commit 1 ------------- Hash Code 2
Commit 3 - Branch 2 commit 2 ------------- Hash Code 3
Commit 4 - Branch 2 commit 3 ------------- Hash Code 4
Commit 5 - Branch 3 commit 1 ------------- Hash Code 5

Branch 1,2,3 are deleted and has been merges with stable. Is there any way that in the commit history I can squash Commit 3 and Commit 4.

The desired result:

Commit 1 - Branch 1 commit 1 ------------- Hash Code 1
Commit 2 - Branch 2 commit 1 ------------- Hash Code 2
Commit 5 - Branch 3 commit 1 ------------- Hash Code 5

When I do git rebase -i, it gives the noop scrren in rebasing.enter image description here

Akshay
  • 153
  • 3
  • 14
  • 1
    You can do `git rebase -i` to perform an [interactive rebase](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). – Chandan Rai Nov 11 '17 at 15:24
  • it gives me noop. I have attached the screenshot also. – Akshay Nov 11 '17 at 15:30
  • 1
    You probably need to correctly specify what you want to rebase onto what. `git rebase --help` to figure that out. – Mort Nov 11 '17 at 15:32

1 Answers1

6

You can do git rebase -i to perform an interactive rebase.

git rebase -i HEAD~4

change

pick  commit 1
pick  commit 2
pick  commit 3
pick  commit 1

into this

pick  commit 1
s     commit 2
s     commit 3
pick  commit 1

save changes and do git push -f

Chandan Rai
  • 9,879
  • 2
  • 20
  • 28
  • Also, can you tell me that suppose this branch is protected and unnecessary commits are from a pull request. And the branch is deleted and merged. Is there any way I can modify a pull request from which the unnecessary commits will be gone. – Akshay Nov 11 '17 at 15:54
  • A PR is always from `source` to `target` branch, once the `source` is deleted after merging into `target`, PR becomes non-existent and can't be changed. Any subsequent changes must go into separate PR. – Chandan Rai Nov 11 '17 at 16:11
  • That is true, but there is a option for restoring the branch where I restored and squashed the extra commits in that branch but it's just I am not getting to work for that PR as I want to squash the unwanted commits into merged branch which is protected. – Akshay Nov 11 '17 at 16:14