Accidentally, I committed 6 times into master instead of creating a new branch.
One wrong commit wouldn't be painful, I would do a simple git reset --soft HEAD~1, stash and re-commit.
But how to solve this problem?
Easier than expected.
Logic:
- Create a new branch based on
master - Remove the commits from
master
Step-by-Step:
- Go into
master:git checkout master - Create a new branch based on
master:git branch my-new-branch - (In
master):git reset --hard HEAD~N, whereNis the number of commits I want to remove,6in my case.
Top comments (4)
Alternatively you can use
git reset --hard origin/masterin step 3. This resets the status of the local repository to the state of remote.@mygeen ,
awesome, thanks for this information.
If you want to use it, first check if your remote is at the proper state.
Creative alternative.
And if i do that in remote?