5

I have a branch A in my repo with 10 commits. What I want is to find a way to delete all commits but leave all changes in the current branch (so the state of the code would be the same but all commits in A would be gone). The purpose is that I now can go over all the changes and cerry pick the once I want and structure better commit messages before I merge back into master. Is this flow even possible?

user3139545
  • 6,882
  • 13
  • 44
  • 87

5 Answers5

10

git reset master will change HEAD and the index to be the same state as master, but leave the working tree untouched (e.g. the current state).

ephemient
  • 198,619
  • 38
  • 280
  • 391
1

git reset commit id will reset the commit to the specified commit id. In this case, you can find the previous commit id from git log and revert to that commit id.

fightingCoder
  • 594
  • 3
  • 7
1

git reset --soft <commit-id> will do what you need. It will move the HEAD to point to but won't change the state of the working tree (so it will leave your files alone). Find out what the commit hash is for the start of A using the log command.

Check out the docs here if you want to find out more about reset.

mamapitufo
  • 4,680
  • 2
  • 25
  • 19
0

Squashing your commits together as a singile unit might help you. Have a look here

Community
  • 1
  • 1
0

YOu have to squash all yor commits into one and after that do reset. Look at this

Community
  • 1
  • 1
Aram810
  • 619
  • 7
  • 21