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?
Asked
Active
Viewed 4,182 times
5

user3139545
- 6,882
- 13
- 44
- 87
5 Answers
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
-
Why use `--hard` when leaving it out will do exactly what he wants, leave all the modifications in his working folder? – Lasse V. Karlsen Apr 07 '17 at 10:35
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