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?
The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case.
You may switch branches with uncommitted changes in the work-tree if and only if said switching does not require clobbering those changes.
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).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With